Sunday, December 9, 2012

Apache Server | htaccess 301 redirect

To make sure search engines consider both www and non-www sites as one, we should create a 301 redirect rule from one to the other. Here's how:

#comments can be added by ignoring lines with this initial character

#this script redirects a specific domain to its www domain

#Options +FollowSymlinks
#RewriteEngine on
#rewritecond %{http_host} ^ [nc]
#rewriterule ^(.*)$$1 [r=301,nc]

#this script redirects generically all www domains to non www-domains

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

No comments:

Post a Comment