How to force non www in htaccess

October 26, 2018

If you want to automatically redirect from www to non-www of your website, in .htaccess then you can add this code (edit your domain as required) to your .htaccess

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.YOURSITE\.com [NC]
RewriteRule ^(.*)$ http://YOURSITE.com/$1 [L,R=301]

Don't forget that you will probably need to enable the rewrite engine for these rules to work. Click the button below to find out how to do this.