2014-12-07 75 views
1

我有一個mod-rewrite的問題。mod_rewrite多個RewriteCond衝突

<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重定向到根。這是如何協同工作的?或者爲什麼它沒有像這樣工作?

+0

那麼你的HTTP服務器的日誌文件說出請求被寫入的內容,以便它們失敗? – arkascha 2014-12-07 14:44:24

+0

我剛添加了部件: RewriteCond%{HTTP_HOST}^example \ .com $ [NC] RewriteRule ^(。*)$ http://www.example.com/$1 [R = permanent] First我只有重定向規則缺少文件/直播的規則。這也工作得很好。但是這兩個RewriteRules一起不適合我。 – blubbering 2014-12-07 14:56:19

+0

您可以嘗試在頁面的HTML標頭中添加以下內容:',以便每個相對URL都從該URL中解析出來,而不是當前頁面的URL。 – anubhava 2014-12-07 17:47:48

回答

1

嘗試在您的重定向中添加一個L標誌。如果你沒有,那麼請求會被標記爲重定向,mod_rewrite將繼續運行其餘的規則。所以這條線需要一個L

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

如果你有你的圖像或樣式相對URL的問題,你可以添加以下到您的網頁的標題:

<base href="/" />