cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Product URL

SOLVED

Custom Product URL

Hello people!

 

Is there a native way or extension that I can automatically customize a URL with information from product registration?

Example below:

 

Product Name: White Sneaker
SKU: 123

In-store URL: www.meusite.com.br/white-sneaker-123.html

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Custom Product URL

Hi @wellington_berbert ,

 

We have Amasty SEO toolkit extension in which they provide the functionality which you needed. We have more features in this extension also. Please have a look once.

 

https://amasty.com/seo-toolkit-for-magento-2.html

 

You can set the Product Url as {ProductName - ProductSku} in the "SEO Meta tags templates" section (in admin configurations). Please check once. 

 

Thanks!

Problem Solved! Click Kudos & Accept as Solution.Screenshot from 2020-05-14 10-01-49.png

View solution in original post

2 REPLIES 2

Re: Custom Product URL

Hello @wellington_berbert ,

 

There is no default facility for mass product URL update.

 

But following script will help you to change all products URL Key.

 

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);    
$obj = $bootstrap->getObjectManager();
$deploymentConfig = $obj->get('Magento\Framework\App\DeploymentConfig');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$productCollection = $objectManager->create('\Magento\Catalog\Model\Product');

$collection = $productCollection->create()
            ->addAttributeToSelect('*')
            ->load();

foreach ($collection as $product){

    $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($product->getId());
    $name = $product->getName();
    $url_product_name = preg_replace('#[^0-9a-z]+#i', '-', $name);
    $url_product_sku = preg_replace('#[^0-9a-z]+#i', '-', $sku);
	
	$url = strtolower($url_product_name) .'-'. strtolower($url_product_sku);
	
    $product ->setUrlKey($url);
    $product->save($pr);

}

If it helps click on Kudos and Accept as Solution.

 

Thank you

Hiren Patel

Re: Custom Product URL

Hi @wellington_berbert ,

 

We have Amasty SEO toolkit extension in which they provide the functionality which you needed. We have more features in this extension also. Please have a look once.

 

https://amasty.com/seo-toolkit-for-magento-2.html

 

You can set the Product Url as {ProductName - ProductSku} in the "SEO Meta tags templates" section (in admin configurations). Please check once. 

 

Thanks!

Problem Solved! Click Kudos & Accept as Solution.Screenshot from 2020-05-14 10-01-49.png