.htaccess规则条件排除

时间:2011-07-16 13:29:27

标签: apache .htaccess mod-rewrite

我使用此规则将任何URL发送到索引,然后分析它并使用我想要的任何URL显示正确的内容。

RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule .* /index.php

如果网址转到/admin/js/css,我需要排除此规则,但我不知道如何排除此规则,因为它没有变量我可以检查 - 实际上我甚至不完全理解这个规则是如何工作的,因为我没有看到它在任何变量中传递。*。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

这将完成这项工作:

RewriteCond %{REQUEST_URI} !^/(index\.php|admin|js|css)
RewriteRule .* /index.php [L]

如果你愿意,你可以把它作为两个独立的条件,但没有真正的需要(只有1个条件它应该更快):

RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !^/(admin|js|css)/
RewriteRule .* /index.php [L]

答案 1 :(得分:0)

尝试此操作,添加额外的RewriteCond

RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !^/(admin|css|js)
RewriteRule .* /index.php

您没有转移.*,而是直接将所有内容重写为index.php。您可能还希望使用[QSA]

附加现有的查询字符串
RewriteRule .* /index.php  [L,QSA]