Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

closed as off-topic by MichelZ, Ward, Jim B, Ladadadada, HopelessN00b Sep 18 at 9:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – MichelZ, Ward, Jim B
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Do you mean redirecting or are you just looking for a CNAME record? –  Christopher Sep 16 '12 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. –  Dan Christian Sep 16 '12 at 13:48
    
Why has it been down voted without any explanation? Not very helpful. –  Dan Christian Sep 16 '12 at 16:35
    
No idea. I upvoted it back up from -1. –  Christopher Sep 16 '12 at 21:45
    
Perhaps because: DNS != HTTP –  Joe Sniderman Sep 8 at 20:15

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Isn't a redirect in the httpd.conf file a less heavy approach then a full mode_rewrite? –  Dan Christian Sep 18 '12 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. –  Jason Floyd Sep 28 '12 at 22:11

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.

share|improve this answer
    
Would you care to explain? –  Michael Hampton Sep 16 '12 at 13:59
    
See my answer below for details on doing this inside apache. –  Jason Floyd Sep 17 '12 at 22:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.