See http://drupal.org/node/107659.

.htaccess file should be:

...

# 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/$1 [R=301,L]

...
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cog.rusty’s picture

I agree and I also suggest a change in the comment.

With the current comment, people (myself included) at first tend to think that if you type www then you won't be able to access the site. This looks better:

# If you want the site to appear always WITHOUT the www. prefix,
# whether the user types it or not, adapt and uncomment the following:

The same for the other case.

ff1’s picture

Version: 5.0-rc2 » 5.x-dev
Status: Active » Needs review
FileSize
1.81 KB

Patch created.

abhigupta’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch. It works.

Please commit it to Drupal.

ff1’s picture

Version: 5.x-dev » 6.x-dev
Status: Reviewed & tested by the community » Needs review

Changed version to 6.x-dev as this issue is certainly still valid in the current HEAD .htaccess file.

I'm not sure if the patch needs to be rerolled for 6.x-dev, so I've also changed the status back to code needs review.

Is this the right way to do this? Or should I have raised a new issue for 6.x-dev? If anyone knows, please let me know.

BioALIEN’s picture

Priority: Normal » Critical

I made this change to all our Drupal sites last month. I was just about to open an issue for this till I came across this one.

+1, this is a must have for D6 and should be back ported to D5.

Setting priority to critical as this actually affects a site's SEO since all 301 links are pointed to the homepage rather than to the correct relative URLs.

webernet’s picture

Title: .htaccess RewriteRule error » RewriteRule for 'www.' always redirects to the front page
FileSize
1.57 KB

Rerolled, and cleaned up the comments.

BioALIEN’s picture

Status: Needs review » Reviewed & tested by the community

And here comes the RTBC :)

ff1’s picture

I'm not sure that the cleaned up comments have helped with the understanding of the no-www issue. We are not forcing users to use www. or not use www., we are just redirecting users if they visit our non-preferred address.

The current patch looks like this:

# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to force users to use (or not to use)
# the 'www.' prefix. Choose ONLY one option:
#
# To force users to access the site WITH the 'www.' prefix,
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#
# To force users to access the site WITHOUT the 'www.' prefix,
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

I think it should be changed to this:

# If your site can be accessed both with and without the 'www.' prefix, you
# 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]

I think this clarifies the no-www problem for both advanced and novice users.

ff1’s picture

Status: Reviewed & tested by the community » Needs review

Changed status back to 'code needs review'.

Senpai’s picture

I agree with the language of the revision. It brings clarity to novices and yet allows more advanced users to easily grasp the either/or scenario without having to think about it. And nobody should make us think. ;)

++ from me, and yeah, this does need to be back-ported to version 5.2. I've been running my personal sites with this same modified rewrite rule for months now, and they seem to work fine. Who's the maintainer for 5.x? Someone should make sure they see this.

Dries’s picture

Looks OK. In the code comments, url should probably be URL. Feel free to roll a patch and to mark this RTBC.

webernet’s picture

FileSize
1.76 KB

Rerolled.

- Expanded comments (not identical to those suggested).

Dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks all!

webernet’s picture

Status: Fixed » Reviewed & tested by the community
FileSize
725 bytes

Just noticed a typo.

Attached is the fix for 6.x

webernet’s picture

FileSize
1.78 KB

Here is the corrected patch against 5.x so it can be back ported.

Dries’s picture

Version: 6.x-dev » 5.x-dev

Committed the typo-fix to CVS HEAD. Thanks.

drumm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 5.

Anonymous’s picture

Status: Fixed » Closed (fixed)