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.

I'm using Amazon Web Services to host my site and since I am going to use the ELB service I will need to redirect all my traffic from http://example.com to http://www.example.com.

Is this possible through the DNS?

I am using Route 53 as my DNS. Any hints would be appreciated.

share|improve this question

migrated from stackoverflow.com Mar 2 '11 at 19:09

This question came from our site for professional and enthusiast programmers.

    
Given the protocol identifiers in your URLs, you can already see that it is impossible. You want two completely unrelated protocols in ways they have not been designed for ;) –  0xC0000022L Mar 2 '11 at 19:33

3 Answers 3

up vote 12 down vote accepted

You cannot do redirects in DNS.

Instead, you need an HTTP server that sends HTTP 301 redirects in response to requests for mysite.com.
Most registrars offer redirect servers; consult yours.

share|improve this answer
    
Indeed my registrar offers a free redirect service. Thank you! –  Alex Mar 2 '11 at 19:42

Even quicker than organicveggie that doesn't require mod_rewrite (but what fun is it running Apache without mod_rewrite?) is that you can just redirect directly from your site config. This requires no webroot to be created at all. This should go within your <VirtualHost *:80> section for this site:

ServerName mydomain.com
ServerAlias *.mydomain.* myotherdomain.* *.myotherdomain.* yetanotherdomain.*
Redirect 301 / http://mymaindomain.com/
share|improve this answer

To supplement SLaks response, a common way to handle this is to use mod_rewrite in Apache and send a 301 redirect. In other words, let ELB send the traffic to an Apache server running on your EC2 instance. Then have Apache send a redirect if the hostname does not include www.

Here's a sample snippet:

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

Hope that helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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