Maintaining Consistent WWW Prefix in Drupal
It has been bothering me for months that visitors arriving at my sites without the www (for example, discover-doug.com rather than www.discover-doug.com) end up at two different places (as far as Google is concerned).
I just stumbled across the solution in the Drupal Issues page which explains how to fix this.
Actually, I was lucky, because Drupal 5.x has a bug in the.htaccess file. There is provision for this - an explanation and some lines to be un-commented, but I had not bothered to read the .htaccess file.
The bug was just fixed, and it showed up on the Drupal Issues page just this evening, and I was, as I say, lucky to see it.
To make this work, first find the following (wrong and misleading) text in the .htaccess file:
# can use one of the following settings to force user to use only one option:
#
# If you want the site to be accessed WITH the www. only, adapt and
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule .* http://www.example.com/ [L,R=301]
#
# If you want the site to be accessed only WITHOUT the www. prefix, adapt
# and uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule .* http://example.com/ [L,R=301]
Replace it with the following correct text:
# can use one of the following settings to redirect users to your preferred url
# (either with or without the ‘www.’ prefix). Choose ONLY one option:
#
# To redirect users to your site WITH the ‘www.’ prefix,
# (eg. a user visiting http://example.com/… will be redirected
# to http://www.example.com/…)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#
# To redirect users to your site WITHOUT the ‘www.’ prefix,
# (eg. a user visiting http://www.example.com/… will be redirected
# to http://example.com/…)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Uncomment the two lines that correspond to either always having a www prefix, or never having a www prefix.
I am hoping this will correct the statistics I see in Google Analytics showing a significant number of referrals from allergy-details.com to www.allergy-details.com!
Comments
No comments:
There are no comments for this post so far.
Post a comment