Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By wdrupal on
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
edit settings.php
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/
This works for me...
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. :)
Thanks :)
Thanks for the code, It did help!
------------------------
www.opensourcepal.org
Code not quite working
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
Yes it is ;-)
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:
This one is more general.
Andre
-------------------------------------------------
http://www.opentravelinfo.com
http://www.aguntherphotography.com
Indeed
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 ;)