When the front controller is dispatched, first off, there’s a check whether Url is the link to product or category. Everything starts from Mage_Core_Controller_Varien_Front->dispatch();

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

classMage_Core_Controller_Varien_FrontextendsVarien_Object

{

//...

publicfunctiondispatch()

{

$request=$this->getRequest();

// If pre-configured, check equality of base URL and requested URL

$this->_checkBaseUrl($request);

$request->setPathInfo()->setDispatched(false);

$this->_getRequestRewriteController()->rewrite();

//...

}

//...

}

//We’re interested in the line: $this->_getRequestRewriteController()->rewrite();

classMage_Core_Model_Url_Rewrite_Request

{

...

publicfunctionrewrite()

{

...

$this->_rewriteDb();

...

}

}

Call the rewrite method in Mage_Core_Model_Url_Rewrite_Request in which the _rewriteDb() is called, then the method loadByRequestPath is called. Load rewrite information for request If $path is array — we must load possible records and choose one matching earlier record in array.

Magento 2

In Magento 2 we have a separate router for processing URL rewrites, that’s why except rewrite mechanism, it’s necessary to understand Routing Mechanism. Each request is sent through the series of routers.

2. CMS RouterCMS Router is used for handling the CMS Pages and it also sets the module name to “cms”, controller name to “page” and action name to “view” so that makes the full path to execute is /vendor/magento/module-cms/Controller/Page/View.php controller

3. URL Rewrite RouterIn Magento 2 UrlRewrite has its own router Magento\UrlRewrite\Controller\Router. using Url Finder to get URL rewrite that matches URL from the database:

The last in the routers loop. It’s used when every other router doesn’t match. In Magento 2 we can create a custom handle for “Not Found” page to display custom content.

In such a manner, if Url put by the user is Url rewrite, so FrontController::dispatch() doesn’t find Url in Base route firstly, then it doesn’t find in cms route and when it gets URL Rewrite, Router calls the method Magento\UrlRewrite\Controller\Router::match() and using Url Finder to get URL rewrite that matches URL from the database and is redirected to request_path from the database received in url_rewrite table.

All in all, having worked with Magento 1 and Magento 2, you can see the difference in Url rewrites. In fact, it doesn’t look so profound, but there are some minor things that need consideration. Hope the article helps to cope with the issue.

Denis is an advanced backend developer who has been dealing with Magento and Prestashop development over the years. As a certified developer, he is constantly improving his skills by passing Magento tests. Having enough experience in e-commerce, Denis makes any web store prosperous by providing excellent development solution

Basically, attribute is a property of the product. You can use it to describe your product for your customers. In Magento 2.0 the functionality to set properties is even more flexible than in its previous versions.

Adding a new attribute in Magento 2.0 is pretty simple. You start by creating a new product or editing an existing one. (more…)