Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on TumblrEmail this to someone

You would like to redirect www.example.com to example.com or example.com to www.example.com then you should try  following htaccess code to make this happen:

Redirect www to no-www

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

It redirects http://www.domain.com/ to http://domain.com//.

Redirect no-www to www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,L]

It redirects http://domain.com/ to http://www.domain.com//.