RewriteCond不懂如何申请!

时间:2011-01-03 02:04:27

标签: mod-rewrite

我有这个

RewriteRule ^articles/([0-9]+)-(.*)\.html$ article.php?id=$1 [L]
RewriteRule .* index.php

由于.htaccess中的[L]问题,我仍然不明白如何应用RewriteCond。帮助!并提前感谢:)

2 个答案:

答案 0 :(得分:1)

关于serverfault有一个很好的参考问题,它解释了规则和条件如何相互作用:
Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

关于Meta的当前讨论所建议的链接。

答案 1 :(得分:0)

我想你正在寻找这样的东西:

RewriteRule ^articles/([0-9]+)-(.*)\.html$ article.php?id=$1 [L]
RewriteCond $0 !=article.php
RewriteRule .* index.php

另一种解决方案是使用第二个article.php的模式排除RewriteRule

RewriteRule !^article\.php$ index.php

但请注意,这将重写任何其他请求(包括其他现有文件)。要征服你可以为第二条规则使用不同的条件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php