How to rewrite URLs that have random% 20 at the end?

I stumbled upon a bunch of backlinks to my site that have the correct URL, except for a random ending space, so the links came out with a trailing %20 , which leads to a page error not found.

I tried options on this:

 RewriteRule ^/%20 / 

but it does not work.

Do you also need a RewriteCond instruction?

Please note that this is IIS 6 server and these are the Wordpress pages that I link to.

Someone please tell him the secret code to get rid of %20 at the end of the url.

Thanks!

+4
source share
1 answer

You can constantly redirect all matching URLs that have a trailing %20 to the same URL without a trailing %20 using the following rule:

If you are using UrlDecoding Off in your iirf.ini , use:

 RedirectRule (.*)%20$ $1 [R=301] 

Otherwise, IIRF will automatically decrypt the URL for you before trying to apply the rules. Therefore you can use:

 RedirectRule (.*)\s$ $1 [R=301] 

To verify this using testdriver.exe :

  • Place the above rule in a file called iirf.ini .
  • Create a file called SampleUrls.txt containing some test URLs, for example:

     / NO REWRITE /%20 REDIRECT 301 / /article NO REWRITE /article%20 REDIRECT 301 /article 
  • Call testdriver with a command like %iirfpath%\testdriver.exe -d .

Please note: testdriver does not decode URLs.

You should get a result similar to the following (I deleted several lines of line feed):

 TestDriver: linked with 'Ionic ISAPI Rewriting Filter (IIRF) 2.1.1.28 x64 RELEASE'. TestDriver: The IIRF library was built on 'Aug 8 2011 02:26:29' Processing URLs...(.\SampleUrls.txt) *** Retrieving server variable that is not supported by TestDriver (SCRIPT_NAME) NO REWRITE '/' ==> -- OK *** Retrieving server variable that is not supported by TestDriver (SCRIPT_NAME) REDIRECT 301 '/%20' ==> '/' OK *** Retrieving server variable that is not supported by TestDriver (SCRIPT_NAME) NO REWRITE '/article' ==> -- OK *** Retrieving server variable that is not supported by TestDriver (SCRIPT_NAME) REDIRECT 301 '/article%20' ==> '/article' OK 0 Errors in 4 Total Trials 
+2
source

All Articles