In the last couple of days, I’ve gotten an inordinate number of requests about how to do a 301 permanent redirect from the non-www version of the person’s domain name to the www version. So instead of copying and pasting the same information over and over again, I can just point people here.
So if you’re using Apache and you want to do this redirect, put the following code in a file called .htaccess in the root directory of your website. Note that it’s more efficient to use httpd.conf file if you have access to it.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
Post a Comment