Friday, 1 April 2016

Redirect non-www to www using .htaccess


Lots of people wants to redirect their web sites from non-www domain to www but can’t find the right way. So Don't need to worry, here is the solution to do that using .htaccess file.

Non-www to www redirect

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Example :(http://yourswebsite.com  to  http://www.yourwebsite.com)
</IfModule>


www to non-www redirect

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$[NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Example :(http://www.yourswebsite.com  to  http://yourwebsite.com)
</IfModule>

Enjoy !  :)

Related Articles

0 comments:

Post a Comment

Prompt Web Solution. Powered by Blogger.