htaccess

In my previous post I mentioned how to redirect non-www to www in htaccess. Now I’ll give codes how to redirect www to non-www in .htaccess

Open your .htaccess file and add the code below.

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

 

Important: add RewriteEngine On at the top of your .htaccess if you don’t have it.

LEAVE A REPLY

Please enter your comment!
Please enter your name here