簡體   English   中英

Wordpress %postname% 永久鏈接中斷 static 主頁 (301)

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

所以我現在遇到這個問題有一段時間了,我似乎找不到合適的解決方案。

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有效。

如果我恢復到普通鏈接,我沒有問題。 我注意到的兩件事是,如果我在主頁末尾添加“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>

所以我通過在我的函數中添加以下內容來解決這個問題。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