htaccess based 301 redirect of non-www to www

///htaccess based 301 redirect of non-www to www

htaccess based 301 redirect of non-www to www

Of cause you want to make a proper 301 redirect from a domain.com to www.domain.com to avoid duplicate content and a bad standing at Google.

If your DNS hosting provider doesn’t provide with a redirect solution, you should make the redirect by yourself.

When using the script based solution (eg. PHP’s header syntax) you either need two sites, or a if-then solution in the code.

mod_rewrite in htaccess is much easier.

Requires the mod_rewrite module is enables, and ‘AllowOverride’ directive to ‘All’ in your virthost setup.

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

/Renzo

By |2011-04-22T21:25:41+00:00January 6th, 2011|Apache, Linux|0 Comments

Leave A Comment