gpt4 book ai didi

php - Wordpress %postname% 永久链接破坏静态主页 (301)

转载 作者:行者123 更新时间:2023-12-05 03:57:43 30 4
gpt4 key购买 nike

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

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

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

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

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

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

但是我需要保持站点 url 路径相对,所以这不是一个理想的修复。

我试过禁用所有插件并将主题更改为默认主题但无济于事。我已经为我的根目录启用了 AllowOverride。我在 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>

最佳答案

所以我通过在我的 functions.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' );

关于php - Wordpress %postname% 永久链接破坏静态主页 (301),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58390947/

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