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:

StevenD

New member
301 redirect from www to non-www
  1. Find your . htaccess file. Find the . htaccess file of your website and download it to your computer. ...
  2. Add the following code into . htaccess file. To make the 301 redirect from www to non-www you have to add the following code into your .htaccess file: RewriteEngine On.