A little of everything professional. This site contains the largest online collection of electronic signature laws and research, my views on Time Management & GTD life hacks for improving productivity, and my After Thoughts on bad decisions and business improvements. Personal thoughts and casual comments are pushed to my SEO project, The World's Greatest Guy.

301 Redirects on the Drupal .htaccess file for non-www to www

in

How to redirect non-www requests to the www.site to reduce risk of SEO penalty

Numerous posts regarding SEO mention that search engines may punish sites for having 'duplicat content' even if that apperant copy is on your own site.

For example a site might be available to both https AND http or http://www AND non-www. Due the magic of the internet this could appear to be two sites with the exact same content. Engines don't like seeing content copied for many of the same reasons that we don't like and often fear copies in the real world. Let's face it duplicates can be scary and can be the cause of spammers putting up multiple copies of info just to reap on banner ads.

Well for all of you Drupal fans out there, here is the code I put into my htaccess file in the root of the drupal install directory.

    # Various rewrite rules.

    RewriteEngine on

      # Modify the RewriteBase if you are using Drupal in a subdirectory and
      # the rewrite rules are not working properly.
      RewriteBase

      #Below in the 301 redirect from non-www to www
      RewriteCond %{HTTP_HOST} ^theworldsgreatestguy.com [NC]
      RewriteRule ^(.*)$ http://www.theworldsgreatestguy.com/$1 [L,R=301]
      RewriteCond %{HTTP_HOST} ^www.worldsgreatestguy.com [NC]
      RewriteRule ^(.*)$ http://www.theworldsgreatestguy.com/$1 [L,R=301]
      RewriteCond %{HTTP_HOST} ^worldsgreatestguy.com [NC]
      RewriteRule ^(.*)$ http://www.theworldsgreatestguy.com/$1 [L,R=301]


I have this alter ego site that I have been Dr Jekylling in the evenings and as you can see I have two URLs for the same site and I wanted all derivitives of them to point to http://www.theworldsgreatestguy.com

I know that this may not be brain surgery but I hope it helps a few people understand how to do it for themselves. So many of the SEO articles I had read just said this was a good idea without spelling it out. So here it is. I am sure there is a way to merge some of the code to make it cleaner but this GTD.


Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p><b><i><blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
Are you really a real person? Oh sure, like I can just trust you. Hey that's ASCII art! Cool.
          _____                 __        __  ____  
_ __ | ___| ___ __ _ \ \ / / | ___|
| '_ \ | |_ / __| / _` | \ \ /\ / / |___ \
| | | | | _| | (__ | (_| | \ V V / ___) |
|_| |_| |_| \___| \__,_| \_/\_/ |____/
Enter the code depicted in ASCII art style.