URL Matching Strategies (PHP)

This is a kind of academic question, so feel free to log out now. I have a Stack breakthrough for streams related to URL / Controller mapping in MVC frameworks - specifically this one:

PHP URL Routing

So far, I can establish two practices:

1: dynamic matching via parsing a string of URLs (exploded by '/')

2: matching the url pattern to the configuration file with available routes

I wanted to get feedback (or links to some other topics / articles) from people regarding their views on how best to approach this task.

+7
php url-routing
source share
2 answers

You can combine both options. Most frameworks do this to control the display of URLs. The first is the default, and the second is an alternative. One of the phrases using it is Zend. you can check zend_router for more details.

+4
source share

I am using your first option.

www.mysite.com/section1

it will explode, and in one file I will check if there is a controller named section1 on the server, if that is the case, I use this to find out what should happen if there is no controller, then I look to see if there is a static file with it is shown by this name, if the script still cannot find anything, it serves the 404 page with some useful information. This worked great for me and gives me a lot of control over how the site reacts to different situations.

0
source share

All Articles