I used Fantastico on my latest Drupal installation. For some reason it set all links to point to the non-www version of the domain name, e.g., my_site.com instead of www. my_site.com. [Space inserted to prevent linking.]

I want all links to point to www. my_site.com and also to use a 301 to redirect all requests for the non-www version to the www version. I know how to do it with htaccess, but the Drupal htaccess is so complicated already I'm not sure how to do it.

Comments

Ayman’s picture

1) Edit sites/default/settings.php and change $base_url to the www version.

2) Place your 301 rewrite rule at the beginning of Drupal's .htaccess.

I think this will do it.

--
Ayman Hourieh
http://aymanh.com/

murph’s picture

rewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
rewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]

I put this code at the end of my .htaccess file. And you can put as many of these in as required for multiple site installations. Sorry if you already knew this, but i guess it will be helpful to others. :)

opensourcepal’s picture

Thanks for the code, It did help!

------------------------
www.opensourcepal.org

decisiveflow’s picture

Hi, thanks for the code. I'm having problems with my front page only. All other pages redirect to the www version, but the front page doesnt. Any ideas? Also, now my drupal webstats records entries from http://decisiv... to be referrers.
Thanks for any help :)

Decisive Flow - Web Design that Helps People Choose You

andre75’s picture

I don't see anything wrong with the code. Have you checked your settings.php?
Also you could have some other things in your .htaccess taking effect before this one does.
Hard to say without looking at your .htaccess code.

Edit:
Actually I am using this:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

This one is more general.

Andre

-------------------------------------------------
http://www.opentravelinfo.com
http://www.aguntherphotography.com

murph’s picture

i have the same where the non-www version is deemed as a referrer...i have never thought this to be a problem, if anything it is interesting to see how many hits are coming in via this ;)