homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Newbie needs help with removal of index.php

 12:05 pm on Aug 25, 2009 (gmt 0)

Hi guys,
I'm trying to sort out a redirect for a client which solves the /index.php problem but the site is built in CS Cart. When I add this bit of code to the htaccess file:

RewriteRule ^index.php$ http://www.domain.com/ [R=301,L]

There are some pages which have the index.php in the url followed by some other directives and my code removes the index.php from those and breaks them. All i want to do is redirect the one instance of [domain.com...] to the root with no other affect on any other url.

This htaccess newb will be very obliged if any of you can help!

Let me know if you want the full htaccess file.



 1:52 pm on Aug 25, 2009 (gmt 0)

> some pages which have the index.php in the url followed by some other directives

What "other directives" specifically?

If you are referring to a query string attached to the URL, then adding

RewriteCond %{QUERY_STRING} =""

ahead of your rule might fix your problem.

However, if you've got index.php defined as your DirectoryIndex (using that directive), then the rule will need further qualification to avoid creating an 'infinite' rewrite/redirect loop. In that case, you'd need to examine THE_REQUEST to be sure that only direct client requests for index.php will be redirected, and that requests for index.php occurring as a result of DirectoryIndex rewriting requests for "/" to "/index.php" won't be redirected.

Luckily, the RewriteCond to do this can replace the one added above, so the code isn't much longer:

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

THE_REQUEST contains the entire client request line, as seen if each entry in your raw server access log file, e.g.
GET /index.php HTTP/1.1

GET /index.php?sid=123 HTTP/1.1



 4:10 pm on Aug 25, 2009 (gmt 0)

Thanks JD.

I added:

RewriteCond %{QUERY_STRING} =""

as you suggested and the site appears to be working fine now. However the DirectoryIndex directive is:

DirectoryIndex index.html index.php

There are no loops? Should I stick with the first code of go for the 2nd option do you reckon?


 4:48 pm on Aug 25, 2009 (gmt 0)

Use the "Live HTTP Headers" add-on for Firefox and Mozilla browsers, examine the HTTP transactions between your browser and your server, and make sure that there is no redirection loop. I would expect it to loop with your DirectoryIndex configured as you describe, and therefore recommend the second version of the code in this case.


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