禁用www重定向WordPress

时间:2016-01-11 05:17:48

标签: php wordpress redirect no-www

我尝试禁用从 www.site.com site.com 的重定向,反之亦然,我使用remove_filter('template_redirect', 'redirect_canonical');但它没有工作。我的 htaccess 很干净。

2 个答案:

答案 0 :(得分:1)

有一种阻止这种情况的硬性方法,但是我个人不喜欢它,因为下次您更新Wordpress时,此更改将得到解决。

您可以编辑文件:第587行的./wp-includes/canonical.php文件,然后删除或注释整个部分:

/**
 * Filters the canonical redirect URL.
 *
 * Returning false to this filter will cancel the redirect.
 *
 * @since 2.3.0
 *
 * @param string $redirect_url  The redirect URL.
 * @param string $requested_url The requested URL.
 */
$redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url );

// // yes, again -- in case the filter aborted the request
if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) {
    return;
}

if ( $do_redirect ) {
    // protect against chained redirects
    if ( ! redirect_canonical( $redirect_url, false ) ) {
        wp_redirect( $redirect_url, 301 );
        exit();
    } else {
        // Debug
        // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) );
        return;
    }
} else {
    return $redirect_url;
}

答案 1 :(得分:0)

enter image description here

只需添加您的网站地址和WordPress地址,如

&#13;
&#13;
http://example.com
&#13;
&#13;
&#13;