2

我需要检查目录是否存在,如果不存在,则回退到动态页面,发布等。

这很接近但不太正确,我不断收到 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 而不是使用缓存。

4

2 回答 2

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>
于 2013-11-12T11:38:15.387 回答
1

This finally ended up being the solution:

<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>

Very close to what Jon Lin provided, thank you for your help.

于 2013-11-12T11:49:45.993 回答