检查目录或回退 htaccess


Checking for Directory or Fallback htaccess

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

这很接近但不太正确,我一直得到 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>

--编辑--

下面的代码现在查找静态缓存文件,但无法回退到已从缓存中删除的项的默认索引.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]

但这会强制所有请求重写为索引.php而不是使用缓存。

你可能想要更多这样的东西:

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

这最终成为解决方案:

<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提供的,谢谢你的帮助。