How can I reset the product URL's so that it will automatically generate new ones based on the product name.

I tried this code inside a new .php file, but that did not work:

require 'app/Mage.php';
$amount = 0;
$model = Mage::getModel('catalog/product');
$products = $model->getCollection();
foreach ($products as $product) {

3 Answers 3


Please follow these steps Jelle.

  1. back up your database

I suppose that your url_key attribute code for product will have attribute_id = 97

You can check by run this query

SELECT attribute_id FROM `eav_attribute` where `attribute_code` = 'url_key' and `entity_type_id` = 4 
  1. run this query

DELETE FROM catalog_product_entity_varchar WHERE attribute_id = 97

  1. Reindex your product URL

Goto System -> Index Management

Reindex catalog URL rewrites

Hope it helps.


You need to use


Instead of


Also: add addAttributeToSelect('name') for add proudtc name at Collection $products = $model->getCollection()->addAttributeToSelect('name');

Change Mage::app(); to Mage::app('YOUR_STORE_CODE') or use Mage::app('admin')

Note: if you have multi store then you need to add store filter on that collection.


Try this:

require_once 'abstract.php';

class Fix_Url extends Mage_Shell_Abstract
    public function run() {
        $products = Mage::getModel('catalog/product')->getCollection();

        foreach ($products as $product) {
                ->updateAttributes(array($product->getId()), array('url_key' => $product->getName()), 0);

$script = new Fix_Url();

Copy in shell subfolder (important!) and run it using:

php -q yourscriptname.php
php -q indexer reindexall

Hope will fix.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.