301 redirects for Directory Owners
October 5th, 2007 by MackEarlier 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
-
RewriteEngine On
On a new line below add
-
RewriteBase /
-
RewriteCond %{HTTP_HOST} ^lobolinks.com$
-
RewriteRule ^(.*)$ http://www.lobolinks.com/$1 [R=301,L]
If your url is non-www based say (http://lobolinks.com). You can use the same code just modify it a bit.
-
RewriteBase /
-
RewriteCond %{HTTP_HOST} ^lobolinks.com$
-
RewriteRule ^(.*)$ http://lobolinks.com/$1 [R=301,L]
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
-
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
-
RewriteRule ^index\.php$ http://www.lobolinks.com/ [R=301,L]
So your final .httacess with both mods applied might look something like this
-
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]
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.
-
# BEGIN WordPress
-
<IfModule mod_rewrite.c>
-
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]
-
</IfModule>
-
-
# END WordPress
Related Post
- Forcing the Wordpress index.php to the Main Url and Avoiding Duplicate Content with a .htaccess - Duplicate Content on a large scale basis can ruin your blog. I blame it on the search engines for not being smart enough to know exactly what yo ...
- How To Add Nofollow to the Wordpress Comments Link - I actually had a damn hard time finding this posted anywhere on the web, so I thought I would share. I don't think I need to tell anyone why thi ...
- Lobo Links Web Directory Blog Launched - I am glad to introduce the Lobo Links Web Directory blog finally. I just want to thank a few people who have helped out with the directory and blog pr ...















By Coolseller on Oct 8, 2007 | Reply
Lobo,
that's really great and Handy MOD.
Surely it help to increase directory quality.
that's best of your's.
cheers...
By Imran on Oct 10, 2007 | Reply
Thanks, I knew the other one, but never realised the index.php issue.
Thanks.
By Mack on Oct 10, 2007 | Reply
I went back and added an example with the use of a sub-directory like /blog/.
Hope it is helpful.
By web on Jan 4, 2008 | Reply
good tips.
Thanks !