Permanently 301 Redirect Domain Including Query Strings and Subdirectories
Though rare, every now and again it is necessary to change the domain name of a site – say someone finally just got that domain name they’ve been after for years, for example.
However, how to change it without losing all of the search engine indexing that existed on the old site . . . especially if the URLs already indexed in search engines contained query strings? If we just do a typical permanent / 301 domainn redirect, all of those pages that used query strings to provide content will simply redirect to the home page of the new domain, which would be dismal for Search Engine Optimization, affiliate links, back links, and other sources of traffic.
Fortunately IIS provides a simple solution. Set up your 301 direct in IIS just as you would do normally, but add two simple parameters: $S (to redirect to the proper subdirectory if present) and $Q (to append the query string during the redirect):
In IIS, under the Properties for the old domain, under the Home Directory tab, select “A redirection to a URL,” enter the fully qualified URL for the new domain . . . followed immediately by these to parameters. Your URL would look like this:
http://www.MyNewDomain.tld$S$Q
Then check the options to send the client to “The exact URL shown above” and “A permanent redirection for this resource.”
Voila! Now all of our old query string driven pages on the old domain will permanently redirect to the new domain like so:
http://www.MyOldDomain.tld/mysubdir/mypage.asp?pid=123 => http://www.MyNewDoain.tld/mysubdir/mypage.asp?pid=123
. . . AND we will have saved the value of the search engine indexing & ranking, affiliate links, and backlinks from other sources for all of those pages when we change domain name.
The situation is more complicated, however, if we aren’t simply changing the domain name, but also perhaps changing platforms as well – say upgrading to a different shopping cart platform, for example. It this case, not only has our domain name changed and needs to be redirected, but our query strings have likely all changed too – or maybe even have been completely replaced by “friendly” URLs that don’t use query strings at all.
In this case we would need to build a page-for-page 301 redirect map as well. For a general overview on this in IIS, see this post. However, there’s more to the picture here as we also need to capture the query strings from the old site and do something with them on a page-for-page basis. Following the general post mentioned above, and using ISAPI_Rewrite as described there, we would need a redirect condition and rule for each page something like the following:
RewriteCond %{QUERY_STRING} ^product_id=123$
RewriteRule ^product.php$ My-Product-Name.aspx [NC,R=301]
May 16th, 2009 at 6:58 pm
My htaccess is like this
RewriteBase //
RewriteRule /?octal\-shop/([0-9]+)/([a-z]+|[a-z-]+).html product.php?prod_name=$2&prodid=$1 [L,NC]
Redirect 301 /octal-shop/12/BoreGeneral.html http://www.mysite.com/octal-shop/12/Bore.html
I have one rewrite rule to redirect all pattern matching urls to product.php?prod_name=$2&prodid=$1its working perfect.
Due to some reason I have few duplicate urls on my site and I am simply trying to implement the 301 redirect so I am writing the 301 redirect, Its also working fine and my server sends 301 response code ( moved permanently) but the problems is it redirects to the expected url but with its parameters also.. take a look at this
Duplicate url : http://www.mysite.com/octal-shop/12/BoreGeneral.html
Redirected to : http://www.mysite.com/octal-shop/12/Bore.html?prod_name=Bore&prodid=12
Expected redirected url : http://www.mysite.com/octal-shop/12/Bore.html because this urls is also rewrited with another rewriterule so dont need to pass 2 parameters in query string..
Can any one help on this issue???