htaccess规则传递的是innecesary变量

时间:2010-01-16 03:54:12

标签: .htaccess

这是文件树:

  • /问题/
  • /problem/index.php
  • 的index.php
  • category.php
  • somefile.php

我在.htaccess中有这两条规则,它位于/

RewriteRule ^somedir$ /somefile.php [L]
RewriteRule ^([a-z-]+)$ /category.php?cat=$1 [QSA,L]

因此...

当/ dir /存在时,我需要添加一个不添加cat = $ 1的规则。

1 个答案:

答案 0 :(得分:2)

只需在第二条规则之前添加RewriteCond即可。基本上,如果以product

开头,请不要运行全部捕获
RewriteRule ^somedir$ /somefile.php [L]
RewriteCond %{REQUEST_URI} !^/product [NC]
RewriteRule ^([a-z-]+)$ /category.php?cat=$1 [QSA,L]

要防止重定向真实文件或目录,请在规则之前添加以下两行:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d