htaccess 对所有内容调用重写规则
这是我的 htaccess 文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Static pages
RewriteRule ^print/([0-9]+)$ index.php?action=PublicDisplayPrint&page_id=$1 [L,QSA]
RewriteRule ^email/([0-9]+)$ index.php?action=PublicDisplayEmail&page_id=$1 [L,QSA]
RewriteRule ^login$ index.php?action=PublicDisplayLogin [L,QSA]
RewriteRule ^search$ index.php?action=PublicDisplaySearch [L,QSA]
RewriteRule ^feedback$ index.php?action=PublicDisplayFeedback [L,QSA]
RewriteRule ^sitemap$ index.php?action=PublicDisplaySitemap [L,QSA]
# Dynamic pages
RewriteRule ^(.*)$ index.php?action=PublicDisplayPage&url=$1 [L,QSA]
它似乎在任何文件(例如 logo.gif)上调用动态页面规则,因此它似乎没有运行第二行和第三行。有什么想法吗?
This is my htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Static pages
RewriteRule ^print/([0-9]+)$ index.php?action=PublicDisplayPrint&page_id=$1 [L,QSA]
RewriteRule ^email/([0-9]+)$ index.php?action=PublicDisplayEmail&page_id=$1 [L,QSA]
RewriteRule ^login$ index.php?action=PublicDisplayLogin [L,QSA]
RewriteRule ^search$ index.php?action=PublicDisplaySearch [L,QSA]
RewriteRule ^feedback$ index.php?action=PublicDisplayFeedback [L,QSA]
RewriteRule ^sitemap$ index.php?action=PublicDisplaySitemap [L,QSA]
# Dynamic pages
RewriteRule ^(.*)$ index.php?action=PublicDisplayPage&url=$1 [L,QSA]
It seems to be calling the dynamic page rule on any file (logo.gif for example) so it doesn't seem to be running the 2nd and 3rd line. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RewriteCond
指令的条件仅属于以下第一个RewriteRule
指令< /a>.因此,在这种情况下,两个RewriteCond
条件仅适用于第一个RewriteRule
而不适用于其他规则,尤其不适用于最后一个规则。因此,将
RewriteCond
指令放在最后一个RewriteRule
指令前面:The condition of a
RewriteCond
directive does only belong to the first followingRewriteRule
directive. So in this case the twoRewriteCond
conditions do only apply to the firstRewriteRule
and not to the other rules, especially not to the last rule.So put the
RewriteCond
directives immediately in front of the the lastRewriteRule
directive:RewriteCond
仅适用于下一个RewriteRule
,因此您的最后 7 条规则将应用于任何请求。您可以重复每个规则的条件,将其放在最后一个规则上,或者放置一个显式规则来按原样提供内容(这更灵活,因为允许您稍后添加更多动态规则):
The
RewriteCond
s are applicable only to the next followingRewriteRule
so your last 7 rules will be applied to any request.You could either repeat the condition for each rule, put it on the last rule or put an explicit rule to serve the content as is (this is more flexible because allows you to add more dynamic rules later):