cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 User Friendly URL

Magento 2 User Friendly URL

suppose if their is any product url with 

 

https://www.testing.com/product-one.html

 

If their is any product attribute eg:- let the attribute is product SKU so the

product SKU value is = 125482

so the requirement is if is it possible to open that product along with SKU as well like

https://www.testing.com/sku/125482/product-one.html

4 REPLIES 4

Re: Magento 2 User Friendly URL

Hi @ersandeepgu,

Greetings!

For adding SKU in product URL
->You need to create a custom module
->override /vendor/magento/module-catalog-url-rewrite/Model/ProductUrlPathGenerator.php
Where in prepareProductUrlKey()

return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() : $urlKey);

you need to replace this file with

return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() . "-" . $product->getSku() : $urlKey);

Hope this will help you solve the issue.

If not, please feel free to reach out to us. 

 

Solved? Click KUDOS and accept it as a solution. 

Thank youSmiley Happy

 

Re: Magento 2 User Friendly URL

Hi namitapare2a78, 

Thanks for your reply and efforts,

  but as per your reply, this is not our requirement, I want "/"  instead of "-" along with product URL key along with sku. 

Thanks.

Re: Magento 2 User Friendly URL

Hi @ersandeepgu,

Greetings!

Then please use "/" where I have used "-". 

Check and let me know if it works for you or not.

 

Solved? Click KUDOS and accept it as a solution.

Thank youSmiley Happy 

Re: Magento 2 User Friendly URL

Hi @namitapare2a78 ,

Greetings!

 
"/" is replaced by "-" in frontend so its not working