Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

301 Redirect in ASP.NET web.config including Parameters

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

like image 873
Jamie Hartnoll Avatar asked Nov 08 '14 17:11

Jamie Hartnoll


1 Answers

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> 
like image 129
b2zw2a Avatar answered Dec 01 '22 15:12

b2zw2a