Using htaccess with Drupal 5

By drupalscoop

301 Redirects using the .htaccess file with Drupal

I have several urls that resolve to our website and it has been said that search engines can punish you for apparently having duplicate content.

The urls are:

  • xyz-tech.com
  • www.xyz-tech.com
  • mymainurl.com
  • www.mymainurl.com

The only one that we need to use is the www.3xlogic.com so everything else should do a 301 redirect to that url. This basically means that if a user enters 3xlogic.com, the rule will change it automatically to www.3xlogic.com and so forth.

If your web host uses apache they may have provided you with htaccess where you can specify what is called a 301 redirect.

You can do this by adding the following lines:

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

This should be placed after the mod_rewrite tag:

<IfModule mod_rewrite.c>
  RewriteEngine on

The .htaccess file is found in your public_html folder. At least it was on mine.

Not knowing exactly how htaccess works I first tried to write the three rewrite conditions (RewriteCond) followed by a single rewrite rule (RewriteRule) but it didn’t work.

It looks like htaccess can give you a lot of control over access features of the apache webserver even if you don’t have full access. So you might see further articles on this topic or you might do a bit of research yourself.

Tags: , ,

One Response to “Using htaccess with Drupal 5”

  1. Josh Says:

    First of all congratulation for such a great site. I learned a lot reading here today. I will make sure i visit this site more often so I can learn more.

    Make your long Urls shorter – Free Url redirection – Hide your affilate URLS

Leave a Reply