301 redirects for Directory Owners

October 5th, 2007

Earlier today I was checking on some new links for the directory and some old ones. I ran across a blog post from Links Juice Blog by eazenet. Eaze was discussing Ten Tips for startup directories. One of the first tips was in regards to using 301s to eliminate duplicate content via the .htaccess file.

I am taking a wild guess and saying that almost all reading will have heard of this. Many things are possible with this smart solution. But one thing many website owners and definately directory owners forget to do is select ONE option for URL rewriting. E.g. Your website is accessible via both http://domain.com and http://www.domain.com.

Now why is this important? Having both URLs working without a rewrite can cause confusion, and often lower your chances of getting higher in SERPs as Search Engines will see two different versions of your site, and eventually you?ll have duplicate content issues..

I thought I might could provide some insight on how to get this done.

Forcing the www

Open your .htaccess in your root directory and find
[html]RewriteEngine On[/html]

On a new line below add
[html]RewriteBase /
RewriteCond %{HTTP_HOST} ^lobolinks.com$
RewriteRule ^(.*)$ http://www.lobolinks.com/$1 [R=301,L][/html]

If your url is non-www based say (http://lobolinks.com). You can use the same code just modify it a bit.

[html]RewriteBase /
RewriteCond %{HTTP_HOST} ^lobolinks.com$
RewriteRule ^(.*)$ http://lobolinks.com/$1 [R=301,L][/html]

Redirecting the Index.php

A common problem I see with some directories is when you click the logo or the home button it takes you to http://www.yoursite.com/index.php. You can also correct this with the .htaccess.

Use the following snipplet, below Rewrite engine on
[html]RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.lobolinks.com/ [R=301,L][/html]

So your final .httacess with both mods applied might look something like this
[html] RewriteEngine On
#—-Redirect index.php———————
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.lobolinks.com/ [R=301,L]
#—-Forcing the www————————
RewriteBase /
RewriteCond %{HTTP_HOST} ^lobolinks.com$
RewriteRule ^(.*)$ http://www.lobolinks.com/$1 [R=301,L][/html]

With a little modification these mods could be applied to any site. I use it on all of mine.

Edit: I applied it to my blog. This will give a good idea how to use it on wordpress and in sub-directories. It took some adapting and working out, but I finally got it to play.

[html]# BEGIN WordPress

RewriteEngine On
#—-Redirect index.php———————
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog/index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.lobolinks.com/blog/ [R=301,L]
#—-Forcing the www————————
RewriteBase /blog/
RewriteCond %{HTTP_HOST} ^lobolinks.com$
RewriteRule ^(.*)$ http://www.lobolinks.com/blog/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

# END WordPress[/html]

Posted in Directory Owner Tips