A(Host) Records with AWS Load Balancer

albertosh picture albertosh · Apr 29, 2011 · Viewed 22.6k times · Source

I have a question regarding AWS Load Balancers.

I can point my CNAME www to my load balancer's DNS perfectly and i know it will always work, BUT I also need to point the @ record to the load balancer so people can access mysite.com instead of www.mysite.com and hit the loadbalancer.

The problem is that the A Records have to point an IP Address so i can't point to the DNS and the IP of the load balancer keeps changing so mysite.com stops working.

Can anyone recommend me a work around for this?

Answer

Havoc P picture Havoc P · Apr 29, 2011

You need a web server that does a redirect instead. i.e. you want to send a 301 "Moved Permanently" from the web server that mysite.com points to, redirecting to www.mysite.com. Then you CNAME www.mysite.com over to Amazon.

Some DNS hosting providers will do this for you, I think GoDaddy does. Otherwise you need to set up a web server you can configure to do this.

The Apache configuration in .htaccess could be for example:

RewriteEngine on
RewriteCond %{HTTP_HOST} mysite.com
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=permanent]

If you have a generic Apache-hosting site that supports .htaccess then you could do that.

Anyway what you're looking for is a redirect.