301 Redirecting to ASP.NET web.config, including options

I am studying using 301 redirects by noticing a bunch of hits in my Google Analytics domain on .asp pages that no longer exist, moving everything to a .NET installation.

After spending a bit of Googling time, I was 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 does not save the task, which makes sense for any meaning, i.e. products.aspx?id=789

+5
source share
2 answers

You must add $Q to the destination URL to save the request. Therefore, 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> 
+8
source

If you have IIS 7 or higher, there is a much more robust solution for rewriting URLs. Using URL Rewrite Module 2.0 , you can create rich redirects that may include the original query string. Following this guide on IIS.net , you can see the option β€œAdd query string” in the screenshot. IIS URL Rewrite Module UI

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

0
source

Source: https://habr.com/ru/post/1206491/


All Articles