How to setup a 301 redirect with Drupal and .htaccess

Grab the feed

School is a twelve-year jail sentence where bad habits are the only curriculum truly learned.

John Taylor Gatto

Recent comments

I was looking for the best way to remove the 'www' from the domain of this site and redirect all users, including search engines, to just ventanazul.com. So I started to play with Apache and the .htaccess mod_rewrite settings and found that the Drupal boys had already thought about this.

Edit .htaccess in your Drupal directory and you will see:

# 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/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [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 and adapt the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

The second option is what I needed, I just added these two lines:

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

That's all, no more 'www'. Pretty simple, uh?

Keep your comments relevant, written in good English and don't spam. Let's create useful and valuable discussions. Markdown is welcome.

Add your comment