I came across this article, How to implement a front controller. The article suggests that a better way to load controllers is to leave it to apache as this is what it was designed for.
So I have a few questions…
- Is using .htaccess a viable alternative to using php for routing requests to controllers?
- Which way is better, faster, modular and portable?
- Has anyone actually implemented an mvc framework in this way?
If so, got any tips? - Does anyone know of any websites that discuss this technique (I couldn’t find anything in
google)?
The primary objection in that article to using a single entry point seems to be:
That’s a very weak argument. Firstly, that’s a terrible way to implement a routing mechanism. Secondly, an application would have to be considerably complex for this to have any measurable effect – and if an application is this complex, it’s likely that any performance hit at the entry point is minimal compared to the execution of the rest of the application.
And consider: if a PHP script for handling the front end of a complex web app is hard to maintain, imagine what the equivalent
.htaccessfile would look like!Finally, you can avoid the issue with a bytecode cache, making the “problem” of loading the script for every request moot.