mod_rewrite:重定向到缓存或脚本

发布于 2025-01-05 17:29:51 字数 571 浏览 3 评论 0原文

对于我正在研究的“缓存”解决方案,我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事↓在人 2025-01-12 17:29:51

尝试将以下内容添加到站点根目录中的 .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

Try adding the following to the .htaccess file in the root directory of your site.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文