如何301将多个域重定向到SSL CloudFront分配?

For example, Say I have the following site in CloudFront under SSL:

https://example.com

How do I 301 redirect a subdomain to it, eg:

www.example.com -> https://example.com

Also, how do I 301 redirect a completely different 'addon domain' to it, eg:

example2.com -> https://example.com

My origin is running PHP in Elastic Beanstalk and I've tried adding rules to my .htaccess file but with no success.