I have a client with a pre-existing Magento site in production mode. When the site was created the client was not informed of the importance of the url keys attribute in that he had to make it SEO-friendly. At this point all the site urls are using a number format e.g. /107 instead of something like /toys. Categories and subcategories are ok to change manually because, the aren't that many but having 1000+ products makes it impossible or at least too time consuming.

Are there any scripts out there to change the url-keys to the product name? e.g. /108 into green-power-ranger assuming the initial product name was GREEN POWER RNAGER

3 Answers 3


Anyone know of a tested script to regenerate url-keys?

error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);
ini_set('memory_limit', '600M');
ini_set('max_execution_time', 1800);
   $products = Mage::getResourceModel('catalog/product_collection')
    $productModel = Mage::getModel('catalog/product');
    foreach ($products as $product) {         
            $productNameLowercase = strtolower($product->getName());
            $productKey = clean($productNameLowercase);             
            $productUpdate = $productModel->load($product->getId());

    function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.

You can use this extension to correct the URL keys and re-generate them in a massive way based on product names, it also adds the UTF-8 URL Key support for your store.


there is also a video here that shows how it dose that.


Magento doesn't do this that easily.

However, if you truncate the core_url_rewrite table and re index. It will fix your issues if you have bad URLs. Here is a tested php script. Then re index ssh preferred method for lots of prodcuts.

// Create connection

// Check connection
        if (mysqli_connect_errno($con))
            echo "Failed to connect to MySQL: " . mysqli_connect_error();

    $sql = "TRUNCATE TABLE core_url_rewrite";
    mysqli_query($con, $sql);

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.