开发者

Apache and backslashes in mod_rewrite

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?


Edit: I just tried this on my webhost and this is handled properly by them. Makes me think it's some setting in httpd.conf.


Probably need AcceptPathInfo off to not get those tolerated as forward slashes.


I was just having this issue on WampServer on Windows. This page had the solution - the AllowEncodedSlashes option that RobertPitt mentions above is the correct one, but it must go in the http.conf file, inside a VirtualHost block, eg:

<VirtualHost *:80>
    AllowEncodedSlashes On
</VirtualHost>

It doesn't work in a .htaccess file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜