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.

e.g. "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.

migrated from stackoverflow.com Apr 20 '11 at 11:00

This question came from our site for professional and enthusiast programmers.

  • What does your rule look like? – halfdan Apr 18 '11 at 16:32

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.