There are several ways to be Rerouting all php requests through index.php or another specified PHP file. It has several benefits for increased customization, SEO, possibly security as you don't reveal too much of the system you're using...
Using this technique, what is best practice / ideal behavior for an OOP based framework to actually show resources, like images, stylesheets, etc. when needed?
So for example
www.mydomain.com/show/23 obviously point all to scripts. But
www.mydomain.com/formvalidation.js point to resources that need to be served with the appropriate header. Also I assume there is a third case, where you point to an error page, be it 404 or something else (some misconfiguration and the request couldn't display a proper result). And maybe you want to be extra thorough and allow for
mydomain.com/login.php to be either treated as
mydomain.com/login or redirect it there, to minimize the number of 404 errors.
So again, for one request you could do one of the three:
- redirect or interpret wrong, but similar urls
- show the respective script
- load the resource
- show an error page
I hope I am making sense so far.
Now of course you could make a big long if/else if statement, and by analyzing
$_SERVER['REQUEST_URI'] for file extension, etc. you can determine which of the three options to take.
Is there a better, OOP oriented solution though?
I'm thinking there might be a request object, that dissects the URL, and the result of that gets used by the router or dispatcher... but who of those should make that decision? Router, Dispatcher, Request Object, Front Controller, or a totally new object?
While thinking about that, I assume that performance might be an issue - in which order you check things, etc. can effect how fast a resource loads. Especially when for example any php script needs to access the DB first, to even be validated (e.g. a CMS where the admin can set up in a db which pages are available and which aren't).
I don't know what keywords to search for and get more information on this subject. I found something about the php webserver, but it specifically said not to use this for production.
And yes, I have tried looking at existing frameworks and how they do it, but their solutions are always so convoluted and complicated right off the bat that I can't make sense out of it... sorry!