Guide to WWW Redirects Using Drupal .htaccess

This blog article covers a few tips for making Drupal Content Management System powered websites more search engine friendly using the .htaccess file. Remember, this file is only used on Apache server, and you can find your .htaccess file in the root of your Drupal installation.

To WWW, or not to WWW?Guide-139792-edited

While it is certainly best practice to have all of your URLs contain the www, what is even it more important is consistency across your site. Your mantra here is: it doesn't really matter which you choose, but stick to your decision! Having some of your site files with and some without the www means that you find yourself an icky scenario: Google and other search engines will index your site files separately depending on whether they have the www or not. Keep your site well represented in search engines…you can't have your www and eat it, too! Another thing to keep in mind when creating links, the two options are to either use site root relative links, or use the full URL (don't forget the www – or the absense of it!).

All Set to Redirect: Three Simple Steps 


Scenario A: Redirecting to www

Step 1: Find the following section in the file
Step 2: Adapt (replace 'example' with your domain name)
Step 3: Uncomment (remove the #)

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

Scenario B: Redirecting without the www

Step 1: Find the following section in the file
Step 2: Adapt (replace 'example' with your domain name)
Step 3: Uncomment (remove the #)

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

Top