Skip to Content

301 redirect non-www to www with htaccess – htaccess rewrite www

htaccess rewrite www

i wish i could use all linux, apache, mysql, php servers for all my projects. things are just way easier than using iis. i love using this block of code in my htaccess file to redirect non www domains to www-domains.

first why is this important. the biggest reason is google and other search engines see both links as actually different websites with the same content. so if you redirect http://example.com to http://www.example.com google knows its only one site and you avoid duplicate content issues.

so in your .htaccess file just add the following code [obviously switch our "example.com" with your domain in the two spots shown below]...

########## Begin non www 301 to www redirect
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes