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.

This question already has an answer here:

I want to redirect all requests from example.com to www.example.com.

Preferably, this should happen at DNS level. I tried using PTR records, but that simply fails, returning a 404.

wwww.example.com is an ALIAS for an Elastic Load Balancer.

What’s the simplest way to achieve this?

share|improve this question

marked as duplicate by pauska, Jenny D, Falcon Momot, Katherine Villyard, Dave M Feb 20 at 20:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
What did you try with PTR records? I'm curious. –  TRiG Feb 18 at 14:25
    
@flavian the poster asked for a DNS rewrite, not a URL rewrite, and he specifically said that he did not care how the URL looked like. –  pauska Feb 18 at 14:36
1  
@flavian for f sake, you said that you want to do the redirect in DNS. My answer explains how to do it in DNS. If you want to redirect the URL then you need a URL rewrite. It has nothing to do with DNS. –  pauska Feb 18 at 14:40
    
Is there any particular reason for doing that? I'd do it the other way around. –  nyuszika7h Feb 18 at 19:43
    
SANs in EV SSL. –  flavian Feb 18 at 19:47
add comment

2 Answers

up vote 3 down vote accepted

If you're already using Route 53, you can use their proprietary alias "record" to solve this problem. With standard DNS, you cannot do this at all and you have to have a web site send a 301 redirect. Of course, you still need to send the 301 redirects or deal with the fact that some requests will come in without the www (though you should send 301s for SEO reasons).

Probably the easiest way to do this is to set up an S3 bucket with the name of the naked domain and configure the bucket properties to redirect from example.com to www.example.com, and then in Route 53 create an alias for the naked domain name that points to that S3 bucket.

share|improve this answer
    
I don't see an ANAME in the route 53 record type option. Could you help me out with more info on how to use that? –  flavian Feb 18 at 14:48
    
Oops, they call it alias now. I've updated the answer. –  Michael Hampton Feb 18 at 15:02
    
It works, many thanks. –  flavian Feb 18 at 15:24
add comment

For a DNS alias you simply need to add a CNAME or A record in DNS. See my answer here: How do I redirect www to non-www in Route53?

For URL-rewriting (as in redirecting the clients to another address) then you need some form of URL rewrite logic done at the webserver. There are several ways of doing this, and it depends on what kind of webserver you use. The most popular is using mod_rewrite with apache. This site is riddled with mod_rewrite questions, a few searches should get what you want.

share|improve this answer
    
I used CNAME on my internal bind9 srv exactly an hour ago, but results are not the same as with url rewrite. When entering this CNAME into the browser address bar, you get exactly that URL, it doesn't change to the url which CNAME points to. I'm using apache mod_rewrite now, sending 301s when there's no www. prefix. –  Kitet Feb 18 at 16:49
add comment

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