Redirecting to WWW With Drupal .htaccess
Below are some tips to help make your Drupal Content Management System driven website more Search Engine friendly using the .htaccess file. Your .htaccess file is located in the root of your Drupal installation. This file is only used on Apache server.
Redirecting to WWW
This is important so that Google and other search engines do not index files separately with and without the www in the URL. It is best practice to have all of your URL’s contain the www, but is acceptable to choose to remove the www as well as long as you set it one way or the other for your entire site. Remember this when creating links, you must either use site root relative links or if you are using the full URL then be sure to include (or exclude) the www.
To modify your .htaccess file to redirect to www find the following section:
# To redirect all users to access the site WITH the ‘www.’ prefix,
# (http://example.com/… will be redirected to http://www.example.com/…)
# adapt and uncomment the following:
#RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
#RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Uncomment the last two lines and replace example with your domain name.
To modify your .htaccess file to redirect users to access your site without the www find this section (right below the first section):
# To redirect all users to access the site WITHOUT the ‘www.’ prefix,
# (http://www.example.com/… will be redirected to http://example.com/…)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Uncomment the last two lines and replace example with your domain name.