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.
Found out the answer myself. The config directive
AllowEncodedSlashesmust be set toonfor 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