我需要检查目录是否存在,如果不存在,则回退到动态页面,发布等等。
这很接近但不太正确,我一直收到Wordpress动态帖子,所以我的情况是错误的:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond wp-content/wp_fast_cache/example.com/%{REQUEST_FILENAME} -d
RewriteRule ^([^?]*) wp-content/wp_fast_cache/example.com/$1 [L]
RewriteRule . /index.php [L]
</IfModule>
- 编辑 -
以下代码现在可以找到静态缓存文件,但无法回退到已从缓存中删除的项目的默认index.php文件。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/wp-content/wp_fast_cache/example.com%{REQUEST_URI} -d
RewriteRule ^([^?]*) wp-content/wp_fast_cache/example.com/$1 [L]
</IfModule>
我在Wordpress htaccess中尝试过默认设置:
RewriteRule . /index.php [L]
但这会强制所有请求重写为index.php而不是使用缓存。
答案 0 :(得分:2)
你可能想要更像这样的东西:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# if the request is already "index.php" pass-through and stop rewriting
RewriteRule ^index\.php$ - [L]
# if the request exists in the fast cache, rewrite it to that
RewriteCond %{DOCUMENT_ROOT}/wp-content/wp_fast_cache/example.com%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}/wp-content/wp_fast_cache/example.com%{REQUEST_URI} -f
RewriteRule ^ wp-content/wp_fast_cache/example.com%{REQUEST_URI} [L]
# else, route through wordpress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
答案 1 :(得分:1)
这最终成为了解决方案:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{DOCUMENT_ROOT}/wp-content/wp_fast_cache/example.com%{REQUEST_URI}index.html -f
RewriteRule ^([^?]*) wp-content/wp_fast_cache/example.com/$1/index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
非常接近Jon Lin提供的内容,感谢您的帮助。