-1

In my AWS Route 53 control panel I simply have 2 A records currently set up for the 'www' and the 'non www' names. Both point to the Elastic IP address associated with my EC2 Instance. This works well and my website is available at both variations but I really want all 'www' to route to the 'non www'.

What is the reccomened method, using AWS Route 53, for routing all traffic that comes to...

www.example.com

to

example.com

5
  • 1
    Do you mean redirecting or are you just looking for a CNAME record? Sep 16, 2012 at 13:05
  • Whatever is the cleanest method. I thought, rather then using .htaccess or Apache config files, that there might be a better way from within AWS Route 53. Sep 16, 2012 at 13:48
  • Why has it been down voted without any explanation? Not very helpful. Sep 16, 2012 at 16:35
  • No idea. I upvoted it back up from -1. Sep 16, 2012 at 21:45
  • Perhaps because: DNS != HTTP Sep 8, 2014 at 20:15

2 Answers 2

1

DNS can't force a redirect. Even a CNAME would just resolve to the same IP address, not cause the browser to redirect to a new URL.

If you're running apache, you can do this using mod_rewrite:

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^/(.*) http://example.com/$1 [R=301,L]

The above checks to see if you're hitting www.example.com and if so, redirects to just example.com with a 301 permanent redirect.

You could do something similar that forced any hostname they've come in with that isn't 'example.com' to be redirected:

RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^/(.*) http://example.com/$1 [R=301,L]

With that, anything that doesn't match exactly "example.com" would be redirected to example.com.

2
  • Isn't a redirect in the httpd.conf file a less heavy approach then a full mode_rewrite? Sep 18, 2012 at 20:29
  • mod_rewrite has great performance. There's a big perf hit if you're using .htaccess files though. I would put the above code in your httpd.conf or vhosts config file, not in an .htaccess files. .htaccess files are read every request, but the main httpd.conf and it's includes are only read at startup. Sep 28, 2012 at 22:11
1

It is not the function of DNS to rewrite your web application's URLs. You do this in the web server or in the web application itself.

2
  • Would you care to explain? Sep 16, 2012 at 13:59
  • See my answer below for details on doing this inside apache. Sep 17, 2012 at 22:05

Not the answer you're looking for? Browse other questions tagged .