How to 301 redirect from www domain to non www domain using htaccess

Enable mod_rewrite module in apache.

Setting the “RewriteBase /”, sets the base of the URL to “/”

Replace example.com with your website domain name.



RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]