简体   繁体   中英

Disable www redirect WordPress

I'm trying to disable redirection from www.site.com to site.com and vice-versa, I used remove_filter('template_redirect', 'redirect_canonical'); but it didn't work. my htaccess is clean.

There is hardcore way to stop this, but I personally don't like it, because next time you update your Wordpress, this change will be fixed.

You can edit the file: ./wp-includes/canonical.php on line 587 and just remove or comment the whole section:

/**
 * 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;
}

在此处输入图像描述

Just Add Your Site address AND WordPress address like

 http://example.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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