Home » Categories » General Questions

How to redirect all non-www requests to my site to the www version?

For making http://domain.com to http://www.domain.com, all you need to do is add the following code to your .htaccess file:

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

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

 ​The above code causes the server to check that the domain name portion of the URL is example.com. If it is, the visitor will be sent to www.example.com instead.

Attachments Attachments
There are no attachments for this article.