mod_rewrite:重定向到缓存或脚本
对于我正在研究的“缓存”解决方案,我的 mod_rewrite 配置遇到了一些麻烦。我有一个名为“cache”的目录,其中包含已编译的 html 文件。我还有一个处理所有请求的index.php 文件。
现在所有请求都被重写到index.php文件中,例如:“/articles”=>; index.php?q=文章。
但现在我希望它重写为“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>
提前致谢:)
I'm having some troubles with my mod_rewrite configuration, for a "cache" solution that I'm working on. I have directory called "cache" with compiled html files. I also have an index.php file which handles all the requests.
Right now all requests are rewritten to the index.php file like: "/articles" => index.php?q=articles.
But now I want it to rewrite to "cache/articles/index.html" if it exists, or else just fall back and rewrite to the index.php script.
I have messed around with the rewrite for a while know, but I can't get it to work. The rewrite code looks like this now (without anything for the cache):
<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>
Thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将以下内容添加到站点根目录中的
.htaccess
文件中。Try adding the following to the
.htaccess
file in the root directory of your site.