简体   繁体   English

Wordpress %postname% 永久链接中断 static 主页 (301)

[英]Wordpress %postname% permalinks break static homepage (301)

so I am having this issue for a while now, and I cannot seem to find a fitting solution.所以我现在遇到这个问题有一段时间了,我似乎找不到合适的解决方案。

Whenever I enable %postname% permalinks, my static homepage https://example.com/xy stops working and delivers 301 “site is not redirecting properly” errors, while any other posts or pages on the site redirect properly, example https://example.com/xy/about-us works. Whenever I enable %postname% permalinks, my static homepage https://example.com/xy stops working and delivers 301 “site is not redirecting properly” errors, while any other posts or pages on the site redirect properly, example https://example.com/xy/about-us有效。

If I revert back to plain links, I have no issues.如果我恢复到普通链接,我没有问题。 Two things that I've noticed are, if I add “index.php” at the end of the homepage it will load again, example https://example.com/xy/index.php .我注意到的两件事是,如果我在主页末尾添加“index.php”,它将再次加载,例如https://example.com/xy/index.php

%postname% permalinks also work if I set site url inside a wp-config.php like this如果我像这样在 wp-config.php 中设置站点 url ,则 %postname% 永久链接也可以使用

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

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

However I am required to keep site url path relative, so this is not a desired fix.但是,我需要保持站点 url 路径相对,因此这不是所需的修复。

I've tried disabling all plugins and changing theme to default to no avail.我尝试禁用所有插件并将主题更改为默认设置,但无济于事。 I've enabled AllowOverride for my root directory.我已经为我的根目录启用了 AllowOverride。 I have mod rewrite enabled in apache, my .htaccess is generated by WP and looks like this:我在 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>

So I worked around this issue by adding following into my functions.php所以我通过在我的函数中添加以下内容来解决这个问题。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' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM