Forcing the Wordpress index.php to the Main Url and Avoiding Duplicate Content with a .htaccess
November 28th, 2007 by MackDuplicate 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 you want, but in any case you can easily avoid this problem with your Wordpress .htaccess. In reality what you are doing is forcing a www. or non-www. prefix for your domain. (ie www.lobolinks.com OR lobolinks.com).
(seen end of post for code)
Forcing that Wordpress index.php to the main URL easy
Most search engines obviously can not determine your targeted prefix or that index.php is the same as main url. The good news is that by making some small changes in your .htaccess you can correct this problem and search engines will follow suite.
Check out these examples
http://www.lobolinks.com/index.php
http://www.lobolinks.com/blog/index.php
Here is the code for both Hacks
Be sure to change the urls to match your site. If you have any problems let me know or catch me on MSN. This was tested on 2.2.2 and 2.3.1
-
# 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
- 301 redirects for Directory Owners - 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 wa ...
- 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 ...
- Adding Facebook to Sociable 2.0 For Wordpress - After posting the instructions for adding mixx to sociable 2.0., Matthew Peters from Pandemic Blog requested the needed code for facebook. I ho ...
















By Andy Beard on Nov 29, 2007 | Reply
I haven't decided what I am going to do with .htaccess changes in WP2.3.1 which has a number of rewrite rules built in and I want to avoid conflicts.
Watch out for the script kiddies if you are running 2.2.2
By Mack on Nov 30, 2007 | Reply
Andy, just a little update on this. I upgraded to 3.1 and everything works fine. The only problem I have found is if you allow wordpress to write to your .htaccess.
It overwrites the code and the hack no longer works.