【发布时间】: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