mod_rewrite多个RewriteCond冲突

时间:2014-12-07 14:40:59

标签: apache .htaccess mod-rewrite redirect

我遇到了mod-rewrite的问题。

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent]  
    # For all files not found in the file system, reroute the request to the
    # "index.php" front controller, keeping the query string intact
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>
# IE Cache fix?
ExpiresActive On
ExpiresDefault A1
Header append Cache-Control must-revalidate

重定向不起作用,并且没有显示样式或图像。

如果这三行都被注释掉了,那就可以了:

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^ index.php [L]

但我需要那些将任何错误的entery重定向到root。这是如何协同工作的?或者为什么它不会像这样工作?

1 个答案:

答案 0 :(得分:1)

尝试在重定向中添加L标记。如果您没有,请求将被标记为重定向,mod_rewrite将继续运行其余规则。所以这一行需要L

RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]  

如果您的图片或样式存在相对网址问题,请尝试将其添加到网页标题中:

<base href="/" />