homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Redirecting index.php to root, but no other index

 5:20 pm on Oct 14, 2009 (gmt 0)

Hi all,

I've got a rewrite rule that will redirect www.mysite.com/index.php to www.mysite.com - works fine.

The problem I'm running into now is that I have a forum installed on my site where I need to login to the administration section, and it requires going to admin/index.php - and now the server redirects it to admin/ and so I get thrown into a loop where I can't login.

I've determined the code that is causing this is:

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mysite.com/$1 [R=301,L]

How can I make this play nice?

Thanks for any help



 5:57 pm on Oct 14, 2009 (gmt 0)

Get rid of the ambiguous ".*" pattern, which matches anything, everything, or nothing at all:

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

Note that the extra bits at the end of the RewriteCond pattern allow for fragment identifiers (HTML named anchors) or query strings on "index.php", but do not allow a match on, for example, ".php5" or ".phpx".



 6:21 pm on Oct 14, 2009 (gmt 0)

That's why you're awesome!

Worked like a charm, thanks :)


 8:51 pm on Oct 14, 2009 (gmt 0)

Are there are any index file URLs in any other folders that should redirect but which now do not?


 9:07 pm on Oct 14, 2009 (gmt 0)

Not that I can tell.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved