Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 规则不匹配?_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 规则不匹配?

Apache 规则不匹配?,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我在.htaccess中有以下内容: RewriteEngine On RewriteBase / RewriteRule ^url/(.*)$ url.php?url=$1 [L] RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] 为什么http://mydomain.ext/url/http://www.google.com/与第一条规则不匹配,但与第二条规则匹配 编辑:当我注释掉最后一行时,它似乎起作用,但我当然不能这样做。发生什么事了 Edit2:

我在.htaccess中有以下内容:

RewriteEngine On
RewriteBase /
RewriteRule ^url/(.*)$ url.php?url=$1 [L]
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
为什么
http://mydomain.ext/url/http://www.google.com/
与第一条规则不匹配,但与第二条规则匹配

编辑:当我注释掉最后一行时,它似乎起作用,但我当然不能这样做。发生什么事了

Edit2:如果我把它改成这个,它会工作:

RewriteEngine On
RewriteBase /
RewriteRule ^url/(.*)$ url.php?url=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
有人能解释为什么以前的版本没有按预期工作吗?

可能是因为“线锚的开始”:“^”匹配以“url/”开头的url


例如,尝试一个“
^.*url/(.*)$
”。

请求可能被重写两次:
/url/http://……
→ <代码>/url.php→
/index.php
。将该路径从第二条规则中排除,它应该可以工作:

RewriteCond $1 !=url.php
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

请求URL不是以
URL/
开头吗?e、 g.
http://foo.bar/url/http://www.google.com/
谢谢,正如我在编辑中提到的添加
RewriteCond%{REQUEST\u FILENAME}-f RewriteCond%{REQUEST_FILENAME}-最后一行之前的d
似乎具有相同的效果,但您的解决方案较短。@阿方索:但您的解决方案比我的更一般,并且还将排除任何其他现有文件和目录。