10

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

fredley
  • 32,953
  • 42
  • 145
  • 236
Liron Harel
  • 10,819
  • 26
  • 118
  • 217
  • 1
    Just a little note that might be relevant to viewers of this post: There are some advantages of using a non-naked domain in cloud-hosting environments, since a naked domain (without a 'www') requires you use A records (to a static IP) instead of CNAME (which can be dynamic). – stereoscott Mar 19 '13 at 19:22
  • @stereoscott Within the context of AWS --who is invested in easing cloud-hosting problems-- Route53 addresses that concern by providing Alias Records. [See here](http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingAliasRRSets.html). – Venning Feb 04 '14 at 01:54

3 Answers3

28

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.

Casey Rodarmor
  • 14,878
  • 5
  • 30
  • 33
21

In Route53 you could set up a PTR(Pointer) Record to go from www.yoursite.com to yoursite.com. This is what I use to set up redirection from mydomain.com to www.mydomain.com

Jeff Thomas
  • 4,728
  • 11
  • 38
  • 57
  • 1
    @Jeff Thomas - tried doing this to route non-www to www. Doesn't work. I created a pointer record, with no alias. I also deleted my A Record for the non-www. The page immediately refreshes with a "page cannot be found" error. Whereas my www domain is working perfectly. Is there some other setting that is needed? – nfriend21 Oct 14 '13 at 14:12
  • 9
    This answer is not an appropriate to the question asked. It is impossible to use PTR record as a 301 redirect as it will not act that way. – Stepan Mazurov Feb 14 '15 at 23:02
  • 1
    This does not work, normally the PTR is used for reverse IP to domain name. Also the entry is not deployed in the Route 53 DNS, we can check with `dig @ns-1837.awsdns-37.co.uk subdomain.domain.tld` – Bruno Adelé Sep 11 '15 at 09:13
0

We also have used the WWWizer, which is just a free service that returns all traffic with a www appended to the front of the naked domain. Set the @ record to point to 174.129.25.170 and set up the www cname or the * cname to point to the load balancer / elastic IP domain.