Built-in Magento routers
Web requests are processed by the web server, and are then sent through the entry point of the application. The “webroot” of the app is determined by the directory the web server is looking at, which in Magento’s case ispub
, and since the default file to handle requests is index.php
, this is the entry point of Magento. So every web request in Magento gets sent through this pub/index.php
file. This bootstraps the application, kicking off the app initialization process.
Without getting into too much unnecessary detail, Magento has different routers set up to handle different incoming requests. When a request is matched to a specific router, it is then sent to a matching “route” of that router which handles the remainder of the request.
There are routers for both the frontend and the admin. The main frontend routers are robots
, urlrewrite
, standard
, cms
, and default
.
The robots
router is listed high up the list, and is responsible for handling the output of robots.txt
requests.
The urlrewrite
strictly handles requests that are in the database, which, you guess it, rewrite URLs, usually to ones that are using the standard
router.
The standard
router is responsible for handling almost all of the requests in Magento, and is the main one you will use when creating your own routes.
The cms
router is also fairly heavily used, and has to do with loading content from the database for pages created in the CMS.
And finally, the default
router is the fallback when any other routes are not matched.
Similarly the adminhtml
router is quite a bit simpler, having an admin
route which matches requests made for admin pages, and a default
router used as a fallback.
There is also a router to handle REST API requests.
Magento is extremely extensible, and you can override existing routers, or add in your own if the built-in routers don’t work for you.
For most of your Magento development and throughout this course, you’ll deal mainly with the standard
router.