Amazon Route 53 setup and 301 Redirection setup

2019-03-11 14:18发布

问题:

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

回答1:

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



回答2:

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.



回答3:

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.