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.

random
  • 450
  • 1
  • 9
  • 16
Alex
  • 111
  • 3
  • 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 02 '11 at 19:33

3 Answers3

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.

SLaks
  • 483
  • 7
  • 14
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/
Neal Magee
  • 329
  • 1
  • 7
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.

organicveggie
  • 1,071
  • 3
  • 15
  • 27