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.

  • 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. – kiamlaluno Dec 10 '11 at 15:40

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]
| improve this answer | |
  • 1
    Just keep in mind that .htaccess can be overwritten by upgrades. A better place for this rule is the Apache config file. – mpdonadio Dec 9 '11 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 May 6 '12 at 12:14

@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.

| improve this answer | |

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