Apache和在mod_rewrite的反斜线 [英] Apache and backslashes in mod_rewrite
问题描述
我要处理通过一个脚本(的index.php
的Web根目录)所有传入的请求。
I want to process all incoming requests through a single script (index.php
in web-root).
于是,以下是目前发生的情况:的http://本地主机/富/酒吧/巴兹
So, the following is what currently happens: http://localhost/foo/bar/baz
路由被Apache(通过的.htaccess
)为:的http://localhost/index.php URL =富/酒吧/巴兹
Is routed by Apache (through .htaccess
) to: http://localhost/index.php?url=foo/bar/baz
这工作得很好,但在Firefox中,我能够做到这一点:的http://本地主机/富\
- >注意的反斜杠。
This works well, however, in Firefox I am able to do this: http://localhost/foo\
-> notice the backslash.
和而不是做了Apache,: /index.php?url=foo \
And Apache, instead of doing: /index.php?url=foo\
发出一个一般性的错误页面俗话说:
Emits a generic error page saying:
找不到对象!所请求的网址 在此服务器上找到。如果你 输入的URL手动请检查 拼写,然后重试。
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.
错误404 本地主机的Apache / 2.2.14 (Win32的)DAV / 2的mod_ssl / 2.2.14 OpenSSL的/ 0.9.8l mod_autoindex_color PHP / 5.3.1 mod_a preq2-20090110 / 2.7.1 的mod_perl / 2.0.4的Perl / v5.10.1
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
直接到: HTTP:?//localhost/index.php URL = foo的\
工作没有问题,但
Directly going to: http://localhost/index.php?url=foo\
works without issues, however.
所有的,我已经看到在互联网上的网站似乎能优雅地处理反斜杠(例如,的http://stackoverflow.com/tags/php \\\\\
)。
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\\\\\
).
我认为这种行为的错误,我想迫使Apache正确转发反斜杠。
下面是其全部我的的.htaccess
文件:
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?
编辑:我只是想这对我的虚拟主机提供商,这是由他们妥善处理。让我觉得这是在的httpd.conf
一些设置。
I just tried this on my webhost and this is handled properly by them. Makes me think it's some setting in httpd.conf
.
推荐答案
我只是有这个问题上WampServer在Windows上。 <一href="http://www.jampmark.com/web-scripting/5-solutions-to-url-en$c$cd-slashes-problem-in-apache.html"相对=nofollow>此页面有解决方案 - AllowEn codedSlashes
选项RobertPitt上面提到的是正确的,但必须去在的http.conf
文件,虚拟主机块中,例如:
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>
它不以的.htaccess
文件工作。
这篇关于Apache和在mod_rewrite的反斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!