问题描述
我有一个网站,其中各个部分自行解析请求URL 不(例如vBulletin论坛).我必须向适当的脚本发送请求的.htaccess是:
I have a website where various parts parse request URLs by themselves and some don't (e.g. a vBulletin forum). The .htaccess I have to send requests to the appropriates scripts is:
# wiki, shop, admin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !(.*)\.js
RewriteRule ^wiki/(.*)$ w/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ wiki/ [L,QSA]
RewriteRule ^shop/ /shop/shop.php [NC,L]
RewriteRule ^forum/admincp/pkr/ /forum/admincp/pkr/pkr.php [NC,L]
这不符合我的预期.我忘记了重写条件仅适用于遵循它们的第一条规则.问题是如何将这些 RewriteCond 类别应用于所有这些规则,而不必将其复制粘贴4次?
This doesn't work as I expected. I forgot that the rewrite conditions are only applied to the first rule that follows them. The question is How can I apply those RewriteConditions to all those rules without having to copypaste them 4 times?
这是怎么回事:
- /shop/example被重写为/shop/shop.php 然后
-
/shop/shop.php再次重写为/shop/shop.php(阅读:我们有一个无限循环).如果将此条件应用于该重写规则,则不会发生这种情况,因为/shop/shop.php是实际文件:
- /shop/example is rewritten to /shop/shop.php
/shop/shop.php is then rewritten again to /shop/shop.php (read: we have an infinite loop). This would not happen if this condition was applied to that rewrite rule, because /shop/shop.php is an actual file:
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME} !-f
是的...
推荐答案
反转表达式并将其附加到中断规则:
Invert the expression and attach it to a breaking rule:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} (.*)\.js
RewriteRule ^ - [L]
这篇关于有一些RewriteCond影响多个规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!