nikc.org
nikc.org

Reputation: 16982

.htaccess ignored when url contains encoded forward slash

I encountered some really strange behaviour in Apache. I have a standard "let PHP handle everything which isn't a file or directory" rewrite setup.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

This works as expected except when the URL contains %2F, which is an encoded forward slash (/). Whenever this happens, Apache responds with a 404, which is logical since none of these paths exists. But what I can't understand, is why my rewrite rules in my .htaccess are being ignored.

TL;DR

GET /Foo/bar/baz is served by my PHP-script

GET /Foo/bar%2Fbaz is served by Apache.

Upvotes: 0

Views: 392

Answers (1)

nikc.org
nikc.org

Reputation: 16982

Found out the answer myself. The config directive AllowEncodedSlashes must be set to on for this to work. Otherwise, Apache will respond with a 404 when the URL contains an encoded forward slash or backslash.

http://httpd.apache.org/docs/2.0/mod/core.html#allowencodedslashes

Upvotes: 1

Related Questions