Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Redirect index.php to my domain without looping

im lost on this..

7:40 pm on Oct 26, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 15, 2004
votes: 0


I want to permanently redirect requests to www.mysite.com/index.php to www.mysite.com - I believe i had tried this in the past with:

RedirectPermanent /index.php [mysite.com...]

and this messed up everything, causing an infinite loop.

how can i do this effectively? (right now google lists both as different pages, and i want to avoid the duplicate content penalty..)

9:15 pm on Oct 26, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

The problem with this is that any request for "/" is internally rewritten to index.php by Apache mod_dir if you have index.php in the DirectoryIndex list (the usual set-up), so it's difficult to avoid an infinite loop.

It can be done with mod_rewrite in .htaccess like this:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]

An example of THE_REQUEST looks like this:
GET /index.php HTTP/1.1

It could also be:

HEAD /index.php HTTP/1.0

so a flexible pattern was provided to handle all valid request cases.

THE_REQUEST is the original request from the client (browser or robot). The RewriteCond will only allow the RewriteRule to be invoked if the client actually requested index.php, and not if the current (internal) request is for index.php only as a result of mod_dir's DirectoryIndex internal URL rewrite. While the rule pattern appears to be redundant, it improves the code efficiency because RewriteConds are only processed if the RewriteRule pattern matches.

The first directive may or may not be needed. It may cause a server error if it is needed but missing, or if it not needed but present. This depends on your server, so you may have to test to find out. The first two directives won't be needed if you already have working rewriterules in your .htaccess file.


8:09 pm on Oct 27, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 15, 2004
votes: 0

thank you so much,

this worked great. i was looking for this code for a LONG time. you are the man!