WordPress %postname% 永久链接中断静态主页 (301)



所以我这个问题已经有一段时间了,我似乎找不到合适的解决方案。

每当我启用 %postname% 永久链接时,我的静态主页https://example.com/xy停止工作并提供 301"网站未正确重定向"错误,而网站上的任何其他帖子或页面正确重定向,示例https://example.com/xy/about-us工作。

如果我恢复到纯链接,我没有问题。 我注意到的两件事是,如果我在主页末尾添加"index.php",它将再次加载,例如https://example.com/xy/index.php

%postname% 永久链接也可以工作,如果我在 wp 配置中设置站点 url.php像这样

define( ‘WP_HOME’, ‘http://example.com/xy’ );

define( ‘WP_SITEURL’, ‘http://example.com/xy’ );

但是,我需要保持站点网址路径相对,因此这不是所需的修复程序。

我尝试禁用所有插件并将主题更改为默认值无济于事。 我已经为我的根目录启用了允许覆盖。 我在 apache 中启用了 mod 重写,我的 .htaccess 是由 WP 生成的,看起来像这样:

RewriteEngine On
RewriteBase /xy/
RewriteRule ^index.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /xy/index.php [L]
</IfModule>

所以我通过在函数中添加以下内容来解决这个问题.php

function disable_front_page_redirects($redirect_url) {
if( is_front_page() ) {
$redirect_url = false;
}
return $redirect_url;
}
add_filter( 'redirect_canonical', 'disable_front_page_redirects' );

最新更新