Forcing NonWWW and WWW in .htaccess

How to force WWW to NONWWW or NONWWW to WWW in your .htaccess file.

www to nonwww htaccess


If you want to redirect all your visitors from NONWWW to WWW site then you need to add this piece of code in your .htaccess folder.

Forcing NONWWW

If you have installed DirectoryInfographics in your root folder then paste the following code after RewriteBase /

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


If you have installed DirectoryInfographics in your sub folder then paste the following code after RewriteBase / but replace demo with your subfolder name.

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


Forcing WWW

If you have installed DirectoryInfographics in your root folder then paste the following code after RewriteBase /

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


If you have installed DirectoryInfographics in your sub folder then paste the following code after RewriteBase / but replace demo with your subfolder name.

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