Amazon Route 53 setup and 301 Redirection setup

Idan Shechter picture Idan Shechter · Jul 7, 2012 · Viewed 21.6k times · Source

I've setup my site on Amazon EC2 server. I am using Route 53 and the servers DNS have already propagated correctly when I set them on Godaddy. I have a few problems. AT the end results I want to make 301 redirect from WWW to NON-www (from www.domain.com to domain.com). I want that redirection to be applicable to all paths (ie. www.domain.com/folder/ to domain.com/folder).

In my current configuration I've setup A record for domain.com to point to the Elastic IP address that I've assigned for my server. When I put the domain.com (without www) in the URL it works great and the site loads. I've also setup the www.domain.com as A record to point to the same IP address.

In IIS7.5 I've set up a Redirection rule (after I've installed the "URL Rewrite" IIS module.

Here's is the rule:

Request URL: Matches the Pattern
Using: Wildcards
Pattern: (.*)
Logical grouping: Match All
Input {HTTP_HOST}
Type: Matches the PAttern
Pattern: www\.mydomainname.com\.com
Action Type: Redirect
Redirect URL: mydomainname.com{R:1}
Redirect Type: 301

When I run my site with 'www' it returns www.mydomain.com/mydomain.commydomain.commydomain.com ,etc...

I don't 'know if the problem is with the URL rewrite, Route 53 settings or both. I want to setup the Route 53 and Redirection rules correctly so my site will redirect all www request to non-www URLs. Furthermore, I wanted to know if it's a good practice to use A record for both www and the main domain in Route 53.

update: I removed the rewrite RULE an it still returns that long url.

update2: I created a CNAME for www and pointed it to the public DNS of the EC2 server and www now works. But I still need the www to non-www redirection rule.

Thanks

Answer

Casey Rodarmor picture Casey Rodarmor · Feb 3, 2013

I think you can do what you want with S3 static website hosting. You can point www.domain.com to an empty S3 bucket with a catch-all redirection rule: http://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html

As an added bonus, it will take load off of your EC2 instance.