
I recently encountered a scenario where a simple 301 redirect was setup in IIS which winded up breaking Google Analytics for AdWords tracking. What happened is that a 301 redirect was setup in order to combine www.website.com and website.com into one as www.website.com. This is a standard SEO tactic used to ensure that search engines only see one version of a website. This prevents duplicate content issues and focuses any PageRank received from inbound links to one site.
Here is the correct way to setup a 301 redirect in IIS:
Guess what – you just broke your website. Here’s how; If a backlink to your site uses a deep link, like website.com/folder/page.html and you set your redirect to www.website.com then anyone clicking that backlink will be sent directly to the root of your site (or worse) at www.website.com instead of the deep link page that you intended them to visit.
In order to properly execute a 301 redirect in IIS you must follow the ‘Redirect to:’ URL with $S$Q in order to pass the suffix of the URL to the redirected URL like this http://www.website.com$S$Q (note there is no / after the .com).
This change will allow http://website.com/folder/page.html to redirect to http://www.website.com/folder/page.html properly within IIS.
-Enjoy!
Check out this link if you need to setup 301 redirects in PHP / Apache.
Check out this link if you need more IIS 301 information.
UPDATE: You don’t need to add the $S$Q if you’re using IIS 7, it does this automatically. Consider this post to apply to IIS 6 and older.
12 Responses
acancida
03|Aug|2008 1Brilliant!
Klebson
05|Mar|2009 2This post helped me a lot. I would like to know if there is a solution to do the same thing with https protocol.
Tina
02|Jul|2009 3Is there a way to do this on the web.config side or do you absolutely need to create a duplicate site instance in IIS? Is there a means to do this in code without impacting load performance?
Our sites are hosted by a third party provider, so we don’t have access to IIS. Also, the sites are set up on a load balancer.
admin
07|Jul|2009 4Tina,
Yes, you can use an open source url rewriter for .net to do this.
Thanks,
-Jeff
Gerald
31|Dec|2009 5Arggghhhh – have you considered NOT listing the “incorrect” method but rather listing the PROPER way, then follow that with the incorrect method so that wayward folks will not follow the instructions that specifically state “Here is the correct way to setup a 301 redirect in IIS:”? I think everyone appreciates the valid tutorial you’ve supplied, but it’s a major hassle to explain to my IT guys “look at SEOJEFF’s page for the proper way to do the re-direct, but read the notes below thepart that says “here how to do it”…
Just a personal comment, but it would seem much more helpful to list the proper way and follow it up with the pitfalls afterward.
g
admin
21|Feb|2010 6Interesting point. I will keep that in mind going forward. Sorry if I caused you any trouble.
Christy
24|Jun|2010 7Hello,
I’ve been asked to change an existing site URL to a new URL for the same site. I’m confused as to what is the best way to accomplish this. Do I use a 301 redirect for old incoming links? What IIS settings would have to change because I’m only thinking the current host header would change from the old URL to the new URL on the existing site and after the DNS and ISP changes…I’m good. Is that right? Thank you in advance.
admin
24|Jun|2010 8I would need more information in order to help you. Can you give me an example of what you’re redirecting from and to? Doesn’t have to be your real URL, just make something up.
Christy
24|Jun|2010 9Thank you for your response. Basically I have a website that is http://www.urla.com and they want to change the name to http://www.urlb.com. Same site different name. It’s on IIS and outside of the DNS and ISP changes, the hostheaders of this site need to be http://www.urlb.com. Would that cover this change…or what else to do you do to change an existing URL to a new one on the same website? Thank you again.
admin
24|Jun|2010 10Assuming all the folder & filenames are staying the same you can use my example. Just create a unique site in IIS for http://www.urla.com.
Christy
24|Jun|2010 11Ok so I need to rename existing site first to the new urlb and then create another IIS site and assign the old name urla to it and setup the 301. Thank you!
admin
24|Jun|2010 12Correct – that’s what I would do.
Leave a reply
Search
My Twitter Feed
Recent Posts
Categories
© 2011 site by Jeffrey Nichols