4

I wound up with a bunch of backlinks to my site that have the correct URL, except there was an accidental trailing space so the links came out with a trailing %20, which causes a page not found error.

I tried variations on this:

RewriteRule ^/%20 /

but it's not working.

Is a RewriteCond statement also needed?

Please note this is an IIS 6 server, and these are Wordpress pages that I'm linking to.

Somebody please tell he the secret code to get rid of a %20 at the end of a URL.

Thanks!

marapet
  • 54,856
  • 12
  • 170
  • 184
phil
  • 51
  • 2

1 Answers1

2

You may permanently redirect all concerned urls having a trailing %20 to the same url without the trailing %20 by using the following rule:

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

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

Otherwise, IIRF automatically decodes the URL for you before trying to apply the rules. You can therefore use:

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

In order to test this using testdriver.exe:

  1. Put the above rule in a file called iirf.ini.
  2. 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
    
  3. Call testdriver with a command similar to %iirfpath%\testdriver.exe -d .

Please note: testdriver does not decode URLs.

You should get an output similar to the following (I removed some newlines):

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
marapet
  • 54,856
  • 12
  • 170
  • 184
  • 2
    Much appreciated! I examined the log file, and found it was automatically replacing the %20 with a space, so I modified the above expression slightly, i.e., "RedirectRule (.*)\s$ $1 [R=301]" and it worked great! – phil Aug 17 '11 at 04:45
  • @phil That's because iirf uses by default `UrlDecoding On` - I modified the answer accordingly. – marapet Jan 04 '13 at 11:26