Server Administration & Management

How to Redirect non-www to www domain using .htaccess

If you want to redirect your domain from  http://domain.com  to http://www.domain.com, then add the following lines in the .htaccess file for domain for which you want to set the redirection

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ “http://www.domain.com ” [R=301,L]

March 13, 2011 Posted by | Apache, htaccess | , , | 2 Comments