Apache and backslashes in mod_rewrite

Posted by NuCalTone on Stack Overflow See other posts from Stack Overflow or by NuCalTone
Published on 2011-01-17T01:47:53Z Indexed on 2011/01/17 1:53 UTC
Read the original article Hit count: 484

Filed under:
|
|
|
|

I want to process all incoming requests through a single script (index.php in web-root).

So, the following is what currently happens: http://localhost/foo/bar/baz

Is routed by Apache (through .htaccess) to: http://localhost/index.php?url=foo/bar/baz


This works well, however, in Firefox I am able to do this: http://localhost/foo\ -> notice the backslash.

And Apache, instead of doing: /index.php?url=foo\

Emits a generic error page saying:

Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404 localhost Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1

Directly going to: http://localhost/index.php?url=foo\ works without issues, however.


All the sites that I've seen on the internet seem to be able to handle backslashes gracefully (e.g., http://stackoverflow.com/tags/php\\\\\).

I consider this behavior a bug and I want to force Apache to forward backslashes correctly. Here's my .htaccess file in its entirety:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L]

How can I make this work properly?

© Stack Overflow or respective owner

Related posts about php

Related posts about apache