There is no question that a search engine has changed the game for every store owner whether you have an online or offline business. And this search engine became part of our life the way it provides a solution for any query. In this digital era, if you want to grow more, earn more and to acquire tons of customers, the search engine is the only key to success for the store owner to expand their business without land boundaries. We can say that SEO is a scientific art that consists of universal efforts. And you are not alone in results there thousand, millions and billions of other pages same things. To stand out in the result page, you need to optimize your store, products, and everything that is public and search engine can crawl.
By default Magento 2 generates product url like
https://magecomp.com/magento-2-indian-gst.html
<——- Store name—->/<—-product name—>.html
But sometimes we need to customize this URL for building SEO friendly URL or to organize store products in a better way so it becomes to understand like
https://magecomp.com/magento-2/magento-2-indian-gst.html
<——- Store name—->/<– prefix –>/<—product name—>.html
And the URL extension will be added as per your backend configuration. This makes sense when it comes to SEO and optimizing store. To do the same, follow three steps guide to add a prefix to Magento 2 product page URL.
First, we need to create ‘di.xml’ at the following location and add below code.
app\code\Vendor\Extension\etc\di.xml
After that you need to create one more file that will fetch default Magento URLs so you can override those urls easily. For that purpose you need to create ‘Url.php’ inside your custom extension folder path.
app\code\Vendor\Extension\Model\Url.php
app\code\Vendor\Extension\Controller\Router.php
You can use this code according to your need for generating different custom product URL. If you need any help regarding this code? Simply leave a comment and if this found it helpful smash that stars. Happy Generating!
In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…
In the world of business, understanding financial metrics is crucial for making informed decisions and…
Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…
In this era, businesses are always on the lookout for ways to engage with their…
Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…
E-commerce has transformed the way consumers shop for products and services and interact with businesses.…
View Comments
first all i want to tell that di.xml file is not having any code in it .
secondly i used this code
in my di.xml file .
third it is throwing this error Exception #0 (LogicException): Front controller reached 100 router match iterations
Exception #0 (LogicException): Front controller reached 100 router match iterations
Which file do we have to override in di.xml ,since the code is missing
Would you please update this article for magento 2.4.3
Hi Mage comp ,
i have add the custom prefix successfully i can not add the products when I click on add to cart then page redirect to search the custom prefix of the current product ,I am not able to add products
Hi,
Can you tell me how to solve Magento securities issues?
$productUrl = $this->getUrlInstance()->setScope($product->getStoreId())->getUrl(' ',$params); line is not getting product url in my case I have multiple website and each website have multiple store
Hi,
It is working fine in single default website and single store, but I have 2 website and each website have multiple stores, Issue is that product url key is not showing, In list page url is showing till static not complete.
Thank you very much, everything works!
Não funcionou
Which error you are facing?
I'm having trouble using these codes, I followed the tutorial and it didn't work, I wanted to know if you can pass me the files to download, I see that it's like a module? what did you do, thanks!