homepage Welcome to WebmasterWorld Guest from 50.16.165.62
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
madmatt69




msg:4006995
 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

 

jdMorgan




msg:4007016
 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".

Jim

madmatt69




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

That's why you're awesome!

Worked like a charm, thanks :)

g1smd




msg:4007132
 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?

madmatt69




msg:4007143
 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