5

I'm looking into using 301 redirects having noticed a bunch of hits on my domain on Google Analytics to .asp pages which not longer exist having moved everything over to a .NET setup.

Having spent a bit of time Googling, I have been able to add the following code to my web.config.

<location path="products.asp">
    <system.webServer>
     <httpRedirect enabled="true" destination="https://www.hartnollguitars.co.uk/products.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
</location> 

This is fine and moves everything from products.asp to pproducts.aspx but it does not preserve the querystring, which is essential to make any sense, ie products.aspx?id=789

2 Answers 2

9

You have to add $Q to the destination url to preserve the querystring. So in your case it should look like this:

<location path="products.asp">
    <system.webServer>
     <httpRedirect enabled="true" destination="https://www.hartnollguitars.co.uk/products.aspx$Q" httpResponseStatus="Permanent" />
    </system.webServer>
</location> 
Sign up to request clarification or add additional context in comments.

Comments

0

If you have IIS 7 or greater, there is a far more robust solution to URL rewrites. Using the URL Rewrite Module 2.0, you can create rich redirects that can include the original query string. Following this guide on IIS.net, you can see in the screenshot the "Append query string" option. IIS URL Rewrite Module UI

You also have the option of using the server variable {QUERY_STRING}. Finally, if you used a Regex with groups in your rule's pattern, you can use the variables {R:#} as shown in the screenshot as well.

1 Comment

Thanks Adam,but I'm on a share server so don't have full access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.