tags:

views:

62

answers:

1

In a similar way to codeigniter I want to catch all requests and rewrite them to an index.php file which sites in the root of my web accessible folder. Unlike the examples on codeigniter however I do not want to check whether the file exists before I rewrite it (because I dont want to allow direct access to any files).

I have had partial success using the following rewrite rule:

RewriteRule ^(.*)$ index.php/$1/ [L]

However the only way I can get it to work is by adding a rewrite condition before it which does some sort of check to make sure the request is not for index.php, otherwise I get a 500 internal server error. Ive had a look at the error log and it seems it is due to too much reccursion. I understand that if the request index.php it doesnt matter anyway because they will hit the right file but I dont understand the need for this condition and I feel dirty including it when I dont know why it has to be there?

The working rule is...

RewriteCond %{REQUEST_URI} !^/index.php/

Its also worth mentioning that this rewrite condition worked aswell but again I dont know why its needed!

RewriteCond %{REQUEST_FILENAME} !index.php
A: 

RewriteCond means, the following RewriteRule is only evaluated if these conditions are met. In your case, in words "If the requested URI doesn't start with /index.php, then reroute to index.php".

You need that check, because otherwise you would be rerouting index.php to itself in an infinite loop.

tilman
It is the infinite loop part which confuses me really, I understand I would be rewriting index.php to index.php once, but I dont understand why it would try to do it a second (or third or fourth...) time. I think im probably missing something significant here...
atkaye
It evaluates the RewriteRule for every request. So after your initial request was sent to index.php, the request for index.php is being evaluated as well, again, rerouting to index.php.. and so forth and so on.
tilman
Found a bit more information about recursion for anyone else that is interested... http://wiki.apache.org/httpd/RewriteLooping
atkaye