gpt4 book ai didi

php - 检查目录或回退 htaccess

转载 作者:行者123 更新时间:2023-12-04 04:34:47 25 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于php - 检查目录或回退 htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19924181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com