2

there is a problem when a use logs in after typing "domain.com", clicks on a internal link that leads to "www.domain.com/somthing" and they are no longer logged in until they navigate to "domain.com" again. I just want the system to force the url to add the www at the beginning.

1
  • This is not a question about Drupal, as the answer given here is valid for any website running on Apache, including the ones using Wordpress.
    – avpaderno
    Commented Dec 10, 2011 at 15:40

2 Answers 2

7

Adding this to your .htaccess file will do it...

RewriteCond %{HTTP_HOST} !^www\.YOURDOMAIN\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule (.*) http://www.YOUDOMAIN.com/$1 [R=301,L]
2
  • 1
    Just keep in mind that .htaccess can be overwritten by upgrades. A better place for this rule is the Apache config file.
    – mpdonadio
    Commented Dec 9, 2011 at 23:29
  • 1
    In Drupal 6 this rule is already in the default .htaccess file. You just have to uncomment it. I guess it's the same in Drupal 7.
    – user6966
    Commented May 6, 2012 at 12:14
3

@New Talk is correct.

In Drupal 7 uncomment these lines:

  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Line 83 and 84.

@MPD is also correct. You will need to re-uncomment these everytime you update your drupal core version.

Not the answer you're looking for? Browse other questions tagged or ask your own question.