This happens on only one of my servers, and I haven't been able to nail down the problem. It feels like a configuration related issue, yet I can't reveal any differences between the working and non-working configuration.

An example URL:

In a working configuration, the server has no problem redirecting the above URL to:

In a non-working configuration, Apache simply returns a 404 error. Not cool!

After scouring the web for a few hours, i came across a knowledgeable fellow who really put a dent in this problem. I wish I could remember the link, to give him proper credit.

Essentially, he created two Rewrite Conditions to locate these encoded characters, allow us to Rewrite appropriately:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?\ ]*\?[^%\ ]*\%(25)*(3[Dd]|26)[^\ ]*)\ HTTP/ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(([^%\ ]*\%(25)*([^3].|.[^Ff]))*[^%\ ]*\%(25)*3[Ff][^\ ]*)\ HTTP/

The one missing link was a proper RewriteRule. I cam up with the below, which seems to work in all of my test cases. Essentially, replacing the %3F with a ?.

RewriteRule ^([^\%]+)$1 [R=301,L]

Again, I have a feeling this is a terribly hacky approach to a simple Apache misconfiguration. But, for those of use who can't Google 50 search terms per minute to find a solution, the above is pretty close!


Leave a Reply

Your email address will not be published. Required fields are marked *