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.
2 Answers
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]
-
1Just 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
-
1In 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.– user6966Commented May 6, 2012 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.