Forum Moderators: phranque

Message Too Old, No Replies

Redirecting com/index.php to com

         

pixelhub

3:00 pm on Jun 15, 2007 (gmt 0)

10+ Year Member



hi i am using this rewrite to redirect example.com/index.php to example.com and it works great.

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

the trouble i'm having is that i would like the index files in the sub directories to do the same

example.com/sub/index.php = example.com/sub/
example.com/sub/sub/index.php = example.com/sub/sub/

can any one offer any help with this

Thanks
Craig

[edited by: jdMorgan at 10:48 pm (utc) on June 15, 2007]
[edit reason] example.com [/edit]

jdMorgan

10:01 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just include provisions for any possible subdirectory path in the patterns and then back-reference the path in the substitution:

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

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

[edited by: jdMorgan at 10:46 pm (utc) on June 15, 2007]