RewriteRule for 'www.' always redirects to the front page

ff1 - January 13, 2007 - 22:56
Project:Drupal
Version:5.x-dev
Component:other
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

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]

...

#1

cog.rusty - January 14, 2007 - 03:35

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.

#2

ff1 - January 19, 2007 - 23:20
Version:5.0-rc2» 5.x-dev
Status:active» patch (code needs review)

Patch created.

AttachmentSize
htaccess_11.patch1.81 KB

#3

abhigupta - May 5, 2007 - 04:48
Status:patch (code needs review)» patch (reviewed & tested by the community)

I tested the patch. It works.

Please commit it to Drupal.

#4

ff1 - May 8, 2007 - 12:07
Version:5.x-dev» 6.x-dev
Status:patch (reviewed & tested by the community)» patch (code 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.

#5

BioALIEN - May 8, 2007 - 18:15
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.

#6

webernet - May 8, 2007 - 19:38
Title:.htaccess RewriteRule error» RewriteRule for 'www.' always redirects to the front page

Rerolled, and cleaned up the comments.

AttachmentSize
patch_122.txt1.57 KB

#7

BioALIEN - May 9, 2007 - 02:03
Status:patch (code needs review)» patch (reviewed & tested by the community)

And here comes the RTBC :)

#8

ff1 - May 9, 2007 - 06:58

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.

#9

ff1 - May 9, 2007 - 06:59
Status:patch (reviewed & tested by the community)» patch (code needs review)

Changed status back to 'code needs review'.

#10

Senpai - May 18, 2007 - 00:38

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.

#11

Dries - May 18, 2007 - 07:24

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

#12

webernet - May 18, 2007 - 11:49

Rerolled.

- Expanded comments (not identical to those suggested).

AttachmentSize
patch_124.txt1.76 KB

#13

Dries - May 18, 2007 - 17:44
Status:patch (code needs review)» fixed

Committed to CVS HEAD. Thanks all!

#14

webernet - May 18, 2007 - 17:56
Status:fixed» patch (reviewed & tested by the community)

Just noticed a typo.

Attached is the fix for 6.x

AttachmentSize
patch6x.txt725 bytes

#15

webernet - May 18, 2007 - 18:03

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

AttachmentSize
patch_125.txt1.78 KB

#16

Dries - May 18, 2007 - 22:10
Version:6.x-dev» 5.x-dev

Committed the typo-fix to CVS HEAD. Thanks.

#17

drumm - May 21, 2007 - 01:35
Status:patch (reviewed & tested by the community)» fixed

Committed to 5.

#18

Anonymous - June 4, 2007 - 21:23
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.