Monday, November 16, 2015

How to redirect non-www URLs to www?

In order to redirect all of the requests for example.com to www.example.com, you should set the appropriate rewrite rule. This can be done by adding the following lines at the beginning of the .htaccess file in your public_html folder:


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

From now on, when someone accesses http://example.com he/she will be redirected to http://www.example.com.

No comments:

Post a Comment