How does Apache process a path with a percent-encoded URL in it

apache-2.2mod-rewrite

I ran into an unexpected case of Apache giving me a 404 error instead of letting mod_rewrite handle the path, when one of the percent-encoded path parts was itself a HTTP URL.

For example:

GET /myfolder/http%3A%2F%2Flocalhost%2Fnotify HTTP/1.0

I have an extremely simple rule in the /myfolder/.htaccess file which sends everything that's not a file in /myfolder/ to a script. It works fine with other percent-encoded values, but in this case Apache never processes the RewriteRule from the .htaccess file. I can double-encode the value as a workaround, but it seems that Apache should still process the mod_rewrite phases. I intend the URL merely to be an input parameter to the script.

Here are the (ir)relevant mod_rewrite directives in /myfolder/.htaccess:

RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule .* ./script-the-world.php

The rewrite rules are NOT being processed. In the server configuration I've got RewriteLogLevel 5, etc., and tail -f /var/log/http/rewrite.log shows all my requests to /myfolder/ being rewritten… except for the one mentioned above. I mean to say that something internal is happening in the special case above, but I have no clue what it is. I'm hoping someone might know of another module that is interfering with what I'm trying to accomplish.

This is Apache 2.2.16.

Best Answer

You'll need to enable AllowEncodedSlashes, which will cause Apache to allow URLs with %2F and %5C in them, instead of throwing a 404. You will still, of course, have to make sure that your PHP script is handling the decoding of the URL correctly, as that's not Apache's duty.