How to setup redirects for domain.com to www.domain.com and vice versa ?

  • GNU/Linux
  • 1 year ago

Create a .htaccess file under the root directory and add the code below:

 

Redirect www.domain.com to domain.com

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Redirect domain.com to www.domain.com

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Save the file and exit and give it a try once  [:-)]