2012-02-15 85 views
0

我對我的mod_rewrite配置有一些麻煩,對於我正在處理的「緩存」解決方案。我有目錄稱爲「緩存」與編譯的HTML文件。我也有一個處理所有請求的index.php文件。mod_rewrite:重定向到緩存或腳本

現在所有請求都被重寫爲index.php文件,如:「/ articles」=> index.php?q = articles。

但是現在我想讓它重寫爲「cache/articles/index.html」(如果它存在),否則就退後並重寫到index.php腳本。

我已經搞砸了一段時間的重寫知道,但我無法得到它的工作。重寫代碼看起來現在這個樣子(沒有任何針對高速緩存):提前

<IfModule mod_rewrite.c> 
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !=/favicon.ico 
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 

</IfModule> 

謝謝:)

+0

你會得到什麼錯誤?你能解釋「不工作」嗎?你的Apache錯誤日誌中有什麼?你可以發佈你嘗試緩存的.htaccess代碼嗎? – 2012-02-15 17:07:54

+0

添加緩存的具體問題是什麼?在哪一點,你不知道更進一步?您的緩存使用哪個請求-url文件名稱sheme? – hakre 2012-02-15 17:08:16

+0

[RewriteRule檢查文件在重寫文件路徑中存在]的可能的重複(http://stackoverflow.com/questions/470880/rewriterule-checking-file-in-rewriten-file-path-exists) – hakre 2012-02-15 17:22:10

回答

1

嘗試添加下列到.htaccess文件在您的網站的根目錄。

RewriteEngine on 
RewriteBase/

#if the index.html exists in the cache 
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}/index.html -f [NC] 
#then display it 
RewriteRule^cache%{REQUEST_URI}/index.html [L] 

#other existing rules go here 
+0

謝謝,這使我的天! :) – Jacob 2012-02-15 18:57:39