Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Some search engines make a difference if the site is found in example.com or www.example.com. So it's important to redirect all users from example.com/some-page to www.example.com/some-page, or the other way around.

Is it possible in Drupal 7?

share|improve this question
    
it might be done via .htaccess –  monymirza Nov 16 '12 at 4:59

1 Answer 1

up vote 5 down vote accepted

I found the answer. The .htaccess file contains the following comments.

# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

Uncommenting one of those rewriting rules is all you need to do.

share|improve this answer
6  
Just make sure that you check when you update Drupal core to ensure that the .htaccess file doesn't get overwritten. –  Patrick Kenny Nov 15 '12 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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