How to force redirect www URLs to non-www

Sitebee

Technical SEO
Staff member
To redirect all www. requests to non-www, add the following directive early on in your .htaccess file. This will force any www. requests to use non-www. using an SEO friendly 301 redirect.

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]

Make sure you switch domain.com with the domain name tied to the hosting (cpanel, plesk, direct admin, etc). Alternatively, if you do want to force requests to www. add this directive in your .htaccess file.

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
 
Last edited: