0

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.

1
  • 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 ;) Mar 2, 2011 at 19:33

3 Answers 3

12

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.

1
  • Indeed my registrar offers a free redirect service. Thank you!
    – Alex
    Mar 2, 2011 at 19:42
1

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/
0

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.

You must log in to answer this question.

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