Friday, August 5, 2016

iis 7 - Is it possible to do a 301 redirect AND redirect to the requested resource?



For one of our projects, we're doing a rebranding of the website name, logo, etc...




As such, we need to 301 Moved Permenantly redirect all users from the old domain to the new domain. With IIS7, that's pretty simple. We just create a new website that redirects all traffic to a host-headered domain .. to the new one.



But this loses their original destination resource.



eg.
Old Domain: www.OldDomain.com
New Domain: www.NewDomain.com

User: www.OldDomain.com/user/PureKrome -> 301 --> www.newDomain.com



Notice how it's going to the new domain BUT not to /user/PureKrome?



How can I do this so it goes to the new domain and keeps the original resource request? I'm guessing URL-ReWriter for IIS7 might help?



Also, what happens if I want to do this...



CurrentDomain 1: Domain.com
CorrectDomain 1: www.Domain.com
CurrentDomain 2: AnotherDomain.com

CorrectDomain 2: www.AnotherDomain.com


Is it also possible to have those in the same IIS website? So any URL to domain.com will 301 to www.domain.com



Right now I'm making 2 IIS websites, with a 301 hardcoded (which still means I lose the original resource request, too).



Help!


Answer



RuslanY's Blog has a great post that describes how to do this with the IIS rewriter.




I will quote his Tip #3 :-




Very often you may have one IIS web
site that uses several different host
names. The most common example is when
a site can be accessed via
http://www.yoursitename.com and via
http://yoursitename.com. Or, perhaps,

you have recently changed you domain
name from oldsitename.com to
newsitename.com and you want your
visitors to use new domain name when
bookmarking links to your site. A very
simple redirect rule will take care of
that: view plaincopy to
clipboardprint?










redirectType="Permanent" />





To see an example of how that works
try browsing to
http://www.ruslany.net/2008/10/aspnet-postbacks-and-url-rewriting/.
You will see in the browser’s address
bar that “www” is removed from the
domain name.



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...