开发者

htaccess rewriting all requests to a single controller

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜