What's the purpose or benefit to redirecting all a website access to index.php using htaccess?
There is a number of answer of how to do it, but I can't find a reason or a s开发者_Go百科et of reasons why it's a nice thing to do.
This is called Front Controller Pattern. There are several benefits including:
- making sure that all common resources for all pages are included.
- website resource is managed and the access can be more easily restricted (e.g. admin only)
- makes the web application as a complete whole package, where common things such as session, session cookie and page access control are shared.
You have one central entry point for your application. There is usually one application behind a website, so it feels quite uncomfortable to access it through many many different single scripts.
comfort, using the same bootstrapping code for all your pages without the danger of forgetting to include something in some of your files.
bootstrapping: the code you run at the beginning of each page, like session_start, db connection, ACL checks etc
I agree with the other users answers, in particular, the @thephpdeveloper user focused the attention on an important detail: the Front Controller Patter.
Generally, when you use a framework like Zend Framework, all requests are received by an index.php files wich is responsible to initialize the environment and analize the url requested (extract the module, controller, action, and so on). In such case the index.php file can be viewed as a web application start point.
精彩评论