301 redirects not working in IIS 7

I need to create this 301 redirect rule: /blog/item.asp?n=12817 redirect to /blog/item/12817

I created a rule in the RIS module for the IIS URL with these parameters:

Pattern: ^blog/item.asp\?n=([0-9]+)

Redirect URL: blog/item/{R:1}

When I test it in IIS, it works fine and created this rule in my web.config:

 <rule name="Asp classic Legacy 301 redirect" stopProcessing="true"> <match url="^blog/item.asp\?n=([0-9]+)" /> <action type="Redirect" url="blog/item/{R:1}" appendQueryString="true" /> </rule> 

But still, when I go to /blog/item.asp?n=12817 in the browser, it shows me the error The resource cannot be found. with the text Requested URL: /blog/item.asp

Why is this so? Do I need to switch somewhere?

thanks

0
source share
1 answer

Ok, I created another rule that works:

 <rule name="Asp classic legacy 301 redirect"> <match url="blog/item\.asp$" /> <conditions> <add input="{QUERY_STRING}" pattern="n=(\d+)" /> </conditions> <action type="Redirect" url="blog/item/{C:1}" redirectType="Permanent" appendQueryString="false"/> </rule> 

Still wondering why the Url rewrite module generates rules that don't work?

+2
source

All Articles