I have products using the same URL Keys and I need a way to remove all of the URL Keys, so Magento regenerate them all according to their names.
Magento – Duplicate Product URL Key
magento-1.9producturl-rewrite
Related Solutions
You can do this by using catalog_product_save_befoe event .Here details below
code MageStack_24869.xml
of app\etc\modules\
<?xml version="1.0" ?>
<config>
<modules>
<MageStack_24869>
<codePool>local</codePool>
<active>true</active>
</MageStack_24869>
</modules>
</config>
And config.xml
path app\code\local\MageStack\24869\etc\
and code is
<?xml version="1.0"?>
<config>
<modules>
<MageStack_24869>
<version>0.1.0</version>
</MageStack_24869>
</modules>
<global>
<models>
<mageStack24869>
<class>MageStack_24869_Model</class>
</mageStack24869>
</models>
</global>
<global>
<events>
<catalog_product_save_before>
<observers>
<mageStack24869>
<type>singleton</type>
<class>mageStack24869/observer</class>
<method>updateurl</method>
</mageStack24869>
</observers>
</catalog_product_save_before>
</events>
</global>
</config>
Also Observer.php
code path (app\code\local\MageStack\24869\Model
)
<?php
class MageStack_24869_Model_Observer{
public function updateurl($observer){
//Mage::log('My log entry', null, 'mylogfile.log');
if($observer->getEvent()->getProduct()){
$Product=$observer->getEvent()->getProduct();
$Url='';
if(!is_null($Product->getData('country_of_manufacture'))):
$Url=$Url.$Product->getAttributeText('country_of_manufacture').'-';
endif;
if(!is_null($Product->getData('sku'))):
$Url=$Url.$Product->getData('sku').'-';
endif;
if(!is_null($Product->getData('name'))):
$Url=$Url.$Product->getData('name');
endif;
//Mage::log('My log entry'.$Url, null, 'mylogfile.log');
$Product->setData('url_key',$Url);
}
}
}
Also you can do using below code
https://stackoverflow.com/questions/23987445/how-to-customize-product-url
I was actually looking for a similar solution as I have more than 1.5 millions URL rewrites created for 35 000+ products. All of this caused by categories, subcategories but also many store views.
I just found a FREE extension that seems to work on every Magento version (confirmed up to 1.8.1 from the comments)
I'm using the latest 1.9.1 so I will have to test it out but this extension is preventing creation of all subcategories URLs, invisible and disabled products for which Magento also creates URL rewrites for.
Correction: From the comments on Magento Connect it works fine on version 1.9.1.
Please follow this link, all the details are explained in details:
http://www.dnd.fr/2012/09/magento-patch-how-to-optimize-re-index-processing-time-for-url-rewrite/
On Magento Connect:
Best Answer
You can use the following query to see which products have duplicate URL keys and how many duplicates there are:
There is also a bug in the URL indexer that appends very large numbers to the end of URL's if duplicates exist, so you might want to look into that.
More information: https://erfanimani.com/issues-with-magentos-catalog-url-rewrite-indexer/