RewriteRule变量为空白 [英] RewriteRule variables blank
问题描述
我在htaccess中有几个重写规则.它们在一台服务器上工作,但不在另一台服务器上工作.我的脚本如下(我已经注释掉了网址的样子):
I have a couple of rewrite rules in htaccess. They work on one server but not another. My script is as follows (I've commented out how the urls look):
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/images/
#example.com/regions/fife/
RewriteRule ^regions/([A-Za-z0-9\-\+\']+)/?$ /regions.php?region=$1 [L]
#example.com/regions/fife/dunfermline
RewriteRule ^regions/([^/]+)/([^/]+)$ /regions.php?region=$1&town=$2 [L]
它返回两个变量(region& town),我可以在PHP中进行操作,并抛出适当的内容.我有一台Rackspace服务器,该脚本运行正常,但是在另一台服务器(Freedom2surf)上,它到目前为止只能运行.它不返回变量.我得到一个空白的$ _GET数组...
It returns two variables (region & town) I can manipulate in PHP, and throw up the appropriate content. I have a Rackspace server, and the script works perfectly, but on another server (Freedom2surf) it only works so far. It doesn't return the variables. I get a blank $_GET array...
有什么想法吗? F2S并没有给我任何线索,只是我应该检查我的代码.但是,如果它可以在另一台服务器上工作,那会带来什么呢?是Apache设置不同吗?
Any ideas? F2S aren't giving me any clues, just that I should check my code. But if it works on another server, then what gives? Is it an Apache setting that is different?
推荐答案
这听起来像您在这里发生了mod_negotiation冲突,您需要关闭多视图.有时,默认情况下,Apache默认配置已打开Multiviews
.它的作用是查看请求,例如/regions/1234
和mod_negotiation将注意到存在文件/regions.php
并假定该请求实际上是针对该php文件的.因此它将服务/regions.php/1234
并完全绕过mod_rewrite.您可以使用Options
将其关闭.只需将其添加到您的htaccess文件的顶部即可:
This sounds like you have a mod_negotiation conflict here and you need to turn Multiviews off. Sometimes apache default configurations have Multiviews
turned on by default. What that does is it will look at a request, say, /regions/1234
and mod_negotiation will notice that there is a file /regions.php
and assume that the request is actually for that php file. It'll thus serve /regions.php/1234
and completely bypass mod_rewrite. You can use Options
to turn it off. Just add this to the top of your htaccess file:
Options -Multiviews
这篇关于RewriteRule变量为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!