Redirect www to non-www htaccess

Question

It’s been asked a gazillion times but it’s still not working in my WordPress. I want to redirect everything to https://website.com.
Current code been used:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
</IfModule>

based on this one but I also tried all in this page and of course this other one. Maybe I am missing something but this is what happens no matter what combination I tried:

# http://website.com      -> https://website.com
# https://website.com     -> https://website.com
# http://www.website.com  -> https://www.website.com     #wrong#
# http://www.website.com  -> https://www.website.com     #wrong#

I am starting to wonder whether the let’s encrypt installation has something to do… or even some other modification done in wp-config.php… I added this in the past:

if ( defined( 'WP_CLI' ) ) {
    $_SERVER['HTTP_HOST'] = 'localhost';
}

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');

Any idea?
Thanks

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/redirect-www-to-non-www-htaccess/">

Redirect www to non-www htaccess</a>
0
, , , Adrian Infante 4 months 0 Answers 43 views 0

Leave an answer