2012-02-15 87 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