htaccess calling rewrite rule on everything
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 ru开发者_运维问答le on any file (logo.gif for example) so it doesn't seem to be running the 2nd and 3rd line. Any ideas?
The condition of a RewriteCond
directive does only belong to the first following RewriteRule
directive. So in this case the two RewriteCond
conditions do only apply to the first RewriteRule
and not to the other rules, especially not to the last rule.
So put the RewriteCond
directives immediately in front of the the last RewriteRule
directive:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?action=PublicDisplayPage&url=$1 [L,QSA]
The RewriteCond
s are applicable only to the next following RewriteRule
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):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
#If it's a file or directory, serve as is, without rewriting
RewriteRule ^ - [L]
#Rest of the rules
精彩评论