Ryan McDonnell - Pursuing Web Application Zen

Redirect /index.php to / with WordPress

Tuesday, February 20th, 2007 at 9:28 pm

When evaluting the search engine rankings for some clients with WordPress blogs I noticed that many of the engines were indexing the http://www.domain.com/index.php and http://www.domain.com/ URLs separately. Obviously this is not ideal as it splits up the ranking and authority for that single page into two unique URLs. Having WordPress in the mix complicates the solution because it already adds mod_rewrite rules to the .htaccess file to handle the permalinks for your blog. Here’s the trick to make it work:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule . / [R=301,L]

Add the above rules before the WordPress mod_rewrite rules. The trick here is that the rule matches the actual URL specified in the HTTP request. If you try using a rule that matches REQUEST_URI (or similar) you’ll get an infinitely looping redirect because it conflicts with the WordPress rules.

3 Comments

  1. Dax

    Hey this was a big help. Thanks

    dax

  2. Bri

    Ryan, thanks a lot. I didn’t even think of that before. Thanks for the easy fix!

  3. Markus

    Thank you for the help. That worked with my site.

Leave a Comment

The following tags are allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

About Ryan McDonnell

I am a web application developer living in southern California. Commonly called a “jack of all trades” by collegues, I constantly strive to broaden my knowledge into other fields.
More about Ryan McDonnell »


 Subscribe in a reader

Quick Links & Notes

© 2004-2008 Ryan McDonnell. View my profile on LinkedIn
Some rights reserved under the Creative Commons Attribution-Share Alike 3.0 United States License.