![]() |
How to make visitors to your web site always go to the www version of your domain name. If you are running Apache on Linux, here is an easy way to make sure that visitors stay on www.yourdomian.com and not yourdomain.com. This is especially
important if you have an ssl cert for www.yourdomain.com and want users to stay there (so they will not see a browser alert for wrong domain)!
If you have an existing .htaccess file in your root directory, then just add the code below to it. If you do not have an .htaccess file, then create one
and add the code below to it.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Just replace yourdomain.com and www.yourdomain.com with your domain name.
After you do this, all requests to yourdomain.com will be redirected to www.yourdomain.com!