Mod rewrite 改写规则混乱

Mod rewrite 改写规则混乱,mod-rewrite,Mod Rewrite,我正在努力实现这个简单的事情 我有一些静态页面,应该是 www.domain.com/profile等。。 问题是如何编写重写规则以 会有一些固定的重写 喜欢/家 我希望存在的每个文件都不要被重写 www.domain.com/test.php应转到 test.php 最后,如果找不到,我希望将其重定向到static.php?\u RewriteRule ^/home/?$ /index.php?__i18n_language=$1 [L] RewriteCond %{REQUEST_FILE

我正在努力实现这个简单的事情

我有一些静态页面,应该是
www.domain.com/profile等。。 问题是如何编写重写规则以

会有一些固定的重写 喜欢/家

我希望存在的每个文件都不要被重写 www.domain.com/test.php应转到 test.php

最后,如果找不到,我希望将其重定向到static.php?\u

RewriteRule ^/home/?$ /index.php?__i18n_language=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([^/]+)/?$ /static.php?__i18n_language=$1  
这工作正常,但如果我键入index.php或test.php,甚至是来自其他重定向的马赫数,它会让我进入static.php。。。
请帮忙

我很久没用过这个了,但我发现它应该会有帮助。它是旧脚本的一部分,该脚本生成.httaccess文件,以便仅在找不到文档时从/usr/share/doc重定向: 规则是“检查,如果目标url存在,则离开”:

这是
[L]
的意思,如果符合其中一个条件,就离开。在旧脚本中,有数百条生成的规则(在
[L]
之后)被跳过,因为其中一个条件匹配。在本例中,当找到目标
%{REQUEST\u FILENAME}
时,您将跳过其余规则

因此,我建议,在重新定向规则之前:

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

根据您的描述,您可以使用以下规则:

# stop rewriting process if request can be mapped onto existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteRule ^ - [L]

# rewrite known paths /home, /foo, /bar, etc.
RewriteRule ^/(home|foo|bar|…)$ /index.php [L]

# rewrite any other path
RewriteRule ^ /static.php [L]

谢谢问题是请求文件名没有返回完整路径!通过添加前缀文档根修复了此问题variable@Parhs:哦,是的,这是可能的:“如果服务器在引用
request\u FILENAME
时已确定与请求匹配的文件或脚本的完整本地文件系统路径。否则,例如在虚拟主机上下文中使用时,与
request\u URI
相同的值”(请参阅)
# stop rewriting process if request can be mapped onto existing file
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteRule ^ - [L]

# rewrite known paths /home, /foo, /bar, etc.
RewriteRule ^/(home|foo|bar|…)$ /index.php [L]

# rewrite any other path
RewriteRule ^ /static.php [L]