How do I force my website visitors to be redirected to my main website domain name?

Article Details
URL: https://my.dotcomhost.com/support/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=9
Article ID: 9
Created On: 17 Aug 2006 08:40 PM

Answer You can configure your website to automatically redirect its visitors to one central domain name. This is done with a few lines of code in an ".htaccess" file, file found in your "/var/www/html" (or your "mainwebsite_html") directory. If that file does not exist already, you can create a blank file and name it ".htaccess".

** Warning: modifying this .htaccess file can potentially bring your website down or cause unintended results. Be sure to back this file up before making any changes.

You will want to put in the following code (replacing "DOMAIN.COM" with your domain name):

#--- Start Redirect Code
RewriteEngine On

# Handles regular requests
RewriteCond %{HTTP_HOST} !^www.DOMAIN.COM$ [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://www.DOMAIN.COM/$1 [R=301,L]

# Handles SSL-page requests
RewriteCond %{HTTP_HOST} !^www.DOMAIN.COM$ [NC]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://www.DOMAIN.COM/$1 [R=301,L]
#---/End Redirect Code