Add to Favourites Add to Favourites    Print this Article Print this Article

Redirect domain.com to www.domain.com

If you want to force clients to use www.domain.com, you can redirect them from domain.com to the www version with an .htaccess file.

In your public_html folder, create a file called

.htaccess

and add the code

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


Other versions of the same thing do a negation check to see if the domain is not www.domain.com, but that doesn't work if you have subdomains.. hence the need for the explicit check for the value we don't want.

Was this answer helpful?

Also Read