IIS URL Rewrite Rule or Custom 404 Redirect Invalid URLs with encoded characters

iis-7

A major newspaper just sent out an email linking out site. The problem is they linked the site as http://example.com/Default.aspx%20%20.

The %20%20 seem to prevent triggering the Custom Error Pages in IIS7. I also tried a URL Rewrite rule but it doesn't seem to work either.

How can I redirect invalid URLs that contain %20%20?

Best Answer

Although uncommon, adding spaces (that's the %20, it's a space in URL encoded form) at the end of an URL is perfectly valid. It's pretty easy to use URL Rewrite module to permanent redirect visitors to the correct URL:

<rule name="Redirect" stopProcessing="true">
    <match url="^Default\.aspx  $" />
    <action type="Redirect" url="/Default.aspx" />
</rule>

You can also do a rewrite but I would advise to do a permanent redirect to hopefully not give the wrong URL a change to survive on the internet.