使用 REQUEST_URI 到 RewriteRule 的 RewriteCond 异常与新域不起作用

Joe*_*azz 2 mod-rewrite .htaccess apache-2.2

以下异常不起作用。http://www.domain.com带和不带 /test 重定向到http://www.example.de/foo/,但异常不应该!

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test$
RewriteRule ^(.*)$ http://www.example.de/foo/ [R=302,L]
Run Code Online (Sandbox Code Playgroud)

什么原因?

Joe*_*azz 10

它与规则冲突

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)

在 .htaccess 文件的末尾。

如果我为 index.php 添加一个例外,例如

RewriteCond %{HTTP_HOST} ^www.domain.example$ [NC]
RewriteCond %{REQUEST_URI} !^/test$
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.*)$ http://www.example.org/foo/ [R=302,L]
Run Code Online (Sandbox Code Playgroud)

那么它的工作原理。