In the article, we’re going to compare routing in Magento 1 and Magento 2. Actually, there’s an article containing routing description in Magento 1, so in case you’d like to have a closer look at routing in Magento 1, read our blog. (more…)
Magento allows having “pretty” addresses. It means that instead of the link /catalog/category/view/id/4, we can get /women.html. Such type of links is clear for users and easy to remember. Moreover, it can improve search engine indexing and ranking.
When we create a category or a product, Magento generates SEF Url automatically. Then we can get into category/product editing and set our own SEF Url. Magento has its own Url rewrite manager where we can observe and change all existing SEF Urls into products as well as add custom Url rewrites.
Let’s compare Magento 1 and 2 and define how Url rewrites work. After Magento 1 or 2 installation with simple data, we can see “pretty” links.
Category: /index.php/women.html; /index.php/women/new-arrivals.html
Category: /index.php/women.html; /index.php/women/tops-women.html
As we can see, there’s nothing irregular and Urls are usual. Now product Urls in Magento 2 do not have a category name. You can change it by getting in Store -> Configuration -> Catalog -> Catalog -> Search Engine Optimization -> “Use Categories Path for Product URLs” set to “Yes”. After that Reindex using php bin/magento indexer:reindex. It’s possible to remove index.php from Urls and, as a result, Urls will be simpler and prettier.
Remove index.php from Urls
To enable SEF URLs on Magento 1, go to your Magento admin panel -> System tab -> Configuration -> General section -> Web. Then expand the Search Engines Optimization section and change the value of Use Web Server Rewrites to Yes and save the changes.
For Magento 2, go to the Magento admin panel -> Stores -> Configuration -> General section -> Web. Expand the ‘Search Engine Optimization’ section and change the value of the Use Web Server Rewrites option to Yes and save the changes.
SEF Urls are really good, but where can they lead?
Url structure in Magento 1 and Magento 2 is the same.
Now when entering /women.html, /catalog/category/view/id/4 is called, where catalog – front_name, category – controller, view – action and param &id=4. How did we manage to get /catalog/category/view/id/4 from /women.html. We managed it with the help of Url rewrite mechanism.
Where can URL rewrites be observed from admin panel?
Catalog > URL Rewrite Management
Marketing > SEO & Search > URL Rewrites
In both Magento versions, we can see Request Path column including “pretty” URL and Target Path column containing a real URL path of the definite page. Let’s consider Target Path for categories and products.
Here is everything as before. The links to products and goods are the same. From admin’s point of view, nothing has changed. But it should be mentioned that if we look at the base, there are some changes appeared and Url rewrites are stored in a different way.
Where can Url rewrites be observed in the base?
Now there are two tables, in url_rewrite table, there’re columns url_rewrite_id, category_id, product_id which are separated. The most significant point is that in Magento 2 in url_rewrite table there are not only links to categories and goods, but cms page. In Magento 1 it was stored in cms_page table.