Fresh Request response lifecycle in Magento
Video Lesson: Request response lifecycle in Magento
Learn how the Magento request response lifecycle processes web requests through web server, entry point, front controller, and URL rewrites for optimal SEO and performance.
Published 2 days ago
Share with colleagues:
Lesson Content
Knowing how Magento handles incoming web requests is absolutely crucial to understand how the entire request→response lifecycle works.
So, what actually happens with the request after it hits the web browser?
Web server and SSL termination
The first thing that happens is that the request is sent to a web server, like Nginx, Apache, or HAProxy. This could also be a designated load balancer or proxy server. But the responsibility this server has is to designate exactly what server application is responsible for handling this request.
This server is also responsible for SSL termination, which terminates the SSL/TLS encryption from the client, processing the request before potentially re-encrypting it for internal services.
App entry point & bootstrapper
Let's say we are working with Nginx. The web server will have a configuration set up for all of the applications that are available to handle the request. And one of those will be your Magento or Adobe Commerce application.
The entry point is the specific file pub/index.php
. This public access point is different from the normal index.php
file that is one directory level up. This adds a layer of security to our app, as if we set the entry point to the main index.php
file, the web server would also publicly expose all of the directories and files that are available, and we definitely wouldn't want that.
When the request comes into pub/index.php
, it is now completely in the hands of the Magento application to now figure out how to handle the request. It will pass it off to a Bootstrap
class, which will initiate the Magento application, which is then responsible for determining how to reply to the incoming request.
Front Controller & request matching
Magento's Front Controller then receives the request. It will loop through all of the available Magento routers, and attempt to match the frontName
(which comes from the first URL parameter) to one of these routers.
Adobe Commerce has a specific router hierarchy. Here’s how it looks for frontend
area routers:
robots
- Handles requests for robots.txturlwrite
- Manages custom and system-generated URL rewritesstandard
- Processes module-based routescms
- Handles requests for CMS pagesdefault
- 404 handler when no other router matches
Admin and default routers also exist for adminhtml
area routers.
The first router to successfully match the URL "wins" and handles the request.
When it finds a frontName
match, it will then look at the other parts of the URL, and attempt to match it to a related controller action. If there's a match, the controller action will then run the related execute()
method which determines how to reply to the request. Magento use a few different Action Classes, all of which implement the \Magento\Framework\App\ActionInterface
.
Magento also has an entire layout XML and template file layer, which is responsible for the presentation of this request.
URL rewrites
URL rewrites are also available, which transform complex system paths into user-friendly URLs. They're handled by the Magento_UrlRewrite
module and stored in the url_rewrite
database table.
The key components of this table are:
Request Path - The user-friendly URL (what customers see)
Target Path - The internal system path
Redirect Type - Permanent (301) or Temporary (302), if applicable
Store ID - The store view where the rewrite applies
There are three main types of URL rewrites:
System-generated - Automatically created for products, categories, and CMS pages
Custom - Manually created by administrators
Redirect-based - Created when products/categories are renamed or moved
Custom modules can also register their own URL rewrite handlers.
Administrators can manage URL rewrites through the admin panel at Marketing → URL Rewrites, as well as in the Store Configuration → Catalog → Search Engine Optimization configuration setting.
This entire system helps to create SEO-friendly URLs while also maintaining the MVVM (Model-View-ViewModel) pattern that Magento uses.