Store
Community Documentation

v3 Knowledgebase

How to redirect non-www to www

Place the following code after the line #19 where it said:

PHP:
RewriteEngine On 


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

The contrary is also possible (www to non-www):

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

If you are getting a 500 server error then you will need to use the following code:

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

Where example.com is your domain name.