Unable to get IIS URL rewrite rule to fix% 3F and% 3D in URL

I have a number of inbound links reported by Google Webmaster Tools that contain objects that lead to 404 errors. I would like to create some URL rewriting rules that will work with IIS to take care of this. These rules should work on any page, since some links containing objects can be deep in several folders and be another file, which is index.php.

For example, rewrite rules should be able to handle:

www.mysite.com/index.php%3Fpage%3Dtest

www.mysite.com/folder/somepage.php%3Fvariable%3Dtest

and convert them to:

www.mysite.com/index.php?page=test

www.mysite.com/folder/somepage.php?variable=test

I tried to create my own rules and not very far. I found rules for Apache that handle this, but importing them using the IIS import rules tool does not work.

Here's what works for Apache (now we just need the IIS version):

# If THE_REQUEST contains a URL-path with a percent-encoded "?" and/or a query string with one # or more specific percent-encoded characters, and we're not already in the process of fixing # it, then copy the client-requested URL-path-plus-query-string into the "MyURI" variable. RewriteCond %{ENV:MyURI}>%{THE_REQUEST} ^>[AZ]+\ /([^\ ]+)\ HTTP/ RewriteCond %1 ^([^?]*\?([^%]*(\%(25)*([^3].|.[^D]))*)*\%(25)*3D.*)$ [NC,OR] RewriteCond %1 ^([^?]*\?([^%]*(\%(25)*([^2].|.[^6]))*)*\%(25)*26.*)$ [OR] RewriteCond %1 ^(([^%]*(\%(25)*([^3].|.[^F]))*)*\%(25)*3F.*)$ [NC] RewriteRule ^. - [NE,E=MyURI:%1] # # If any encoded question mark is present in the client-requested URI, and # no unencoded question mark is present, replace the first encoded question # mark, queue up a redirect, and then re-start mod_rewrite processing RewriteCond %{ENV:MyURI} ^[^?]+$ RewriteCond %{ENV:MyURI} ^(([^%]*(\%(25)*([^3].|.[^F]))*)*)\%(25)*3F(.*)$ [NC] RewriteRule ^. - [NE,E=MyURI:%1?%7,E=QRedir:Yes,N] # # If any encoded "=" sign follows the "?", replace it, queue # up a redirect, and re-start mod_rewrite processing RewriteCond %{ENV:MyURI} ^([^?]*\?([^%]*(\%(25)*([^3].|.[^D]))*)*)\%(25)*3D(.*)$ [NC] RewriteRule ^. - [NE,E=MyURI:%1=%7,E=QRedir:Yes,N] # # If any encoded ampersand follows the "?", replace it, queue # up a redirect, and then re-start mod_rewrite processing RewriteCond %{ENV:MyURI} ^([^?]*\?([^%]*(\%(25)*([^2].|.[^6]))*)*)\%(25)*26(.*)$ RewriteRule ^. - [NE,E=MyURI:%1&%7,E=QRedir:Yes,N] # # If we get here, there are no more percent-encoded characters which can # and should be replaced by the rules above, so do the external redirect RewriteCond %{ENV:QRedir} =Yes [NC] RewriteRule ^. http://www.example.com/%{ENV:MyURI} [NE,R=301,L] 

This at least gives us an idea of ​​what to consider when writing rules for rewriting the IIS URL.

+4
source share
1 answer

This rule will work for you:

 <rule name="3f and 3d redirect"> <match url="(.*)(\?|\=)(.*)" /> <action type="Redirect" url="{R:0}" /> </rule> 
0
source

All Articles