【问题标题】:apache htaccess mod_rewrite to check cache folder first then run WordPress index.phpapache htaccess mod_rewrite 先检查缓存文件夹,然后运行 ​​WordPress index.php
【发布时间】:2017-08-13 16:12:52
【问题描述】:

我正在为我自己的 WordPress 插件设置一个非常简单的缓存...我已经在 StackOverflow 和其他地方研究了几天。找到了一些非常接近的很好的答案(寻找图像文件等),但没有针对这个特定场景 - 并且修改其他解决方案不起作用。

除了重写规则之外,我已经完成了所有工作:

http / https 的传入请求

domain.com/page-slug/   OR  domain.com/year/month/page-slug/

需要 htaccess 来首先检查缓存文件夹

domain.com/wp-content/cache/myfolder/page-slug.html

(请注意传入的请求可以是“/page-slug/”或“/page-slug”,并且缓存文件名具有“.html”扩展名以使其成为“page-slug.html”)

如果缓存文件确实不存在,那么就

...go through the usual WordPress index.php process

另外——如果 url 中没有 slug/页面名称怎么办?

ie:首页...可以直接htaccess

domain.com  to  domain.com/wp-content/cache/myfolder/index.html

如果缓存的 index.html 不存在,则转到 WP index.php

有没有办法纯粹使用 .htaccess 规则进行上述缓存检查?任何指导将不胜感激。

(我希望我上面的解释很清楚——我自己也很困惑!哈哈)

更新:

我在htaccess rewrite if file not exists in cache folder by anubhava 中找到了一个很好的答案,并尝试将其修改如下,我认为它很接近,但效果不太好:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# Admin area 
RewriteRule ^admin(.*) admin$1 [L] 

# Check if file *.* exist in the cache foldel 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/cache/ebg/$1 -f [NC] 
RewriteRule ^(.+?)/?$ /cache/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite caching


    【解决方案1】:

    如果上述解决方案不起作用,请联系您的网络托管服务提供商。您很可能没有在您的虚拟主机包上激活 Mod_Rewrite。

    【讨论】:

    • mod_rewrite 已激活——它适用于 WordPress,但上面的代码没有查看 slug + ".html" 的缓存——我只是不知道如何获取它这样做 - 然后如果文件不存在,返回到默认的 WordPress 重写规则。
    猜你喜欢
    • 2012-05-07
    • 2022-11-02
    • 2013-10-26
    • 1970-01-01
    • 2012-10-24
    • 2012-03-08
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多