Welcome to WebmasterWorld Guest from 50.16.68.229

Forum Moderators: Ocean10000 & incrediBILL & phranque

Newbie needs help with removal of index.php

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

5+ Year Member



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)

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



> 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

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

Jim

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

5+ Year Member



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)

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



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.

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month