Magento: how to remove all permanent redirects

31,536

Solution 1

If your store is not live yet, follow this:

  1. Empty/Truncate core_url_rewrite table from Database.

  2. Disable Permanent Redirects from Magento Backend.

  3. Reindex Catalog URL Rewrites and all your URL's will be corrected.

Solution 2

In order to remove all permanent redirects you can:

1) Execute direct query (not recommended):

DELETE FROM core_url_rewrite WHERE options IS NOT NULL AND is_system = 0

2) Do it more gently:

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
try {
    $write->beginTransaction();
    $table = Mage::getSingleton('core/resource')->getTableName('core/url_rewrite');
    $count = $write->exec('DELETE FROM ' . $table . ' WHERE options IS NOT NULL AND is_system = 0');
    $write->commit();
    $this->_getSession()->addSuccess($this->__('Successfully removed %s redirects.', $count));
} catch(Exception $e) {
    $write->rollback();
    $this->_getSession()->addException($this->__("An error occurred while clearing url redirects: %s", $e->getMessage()));            
}

3) Or you can install Custom Product Urls extension which enables you to clear all permanent redirects from admin panel.

Share:
31,536
laketuna
Author by

laketuna

Updated on March 01, 2020

Comments

  • laketuna
    laketuna about 4 years

    We've encountered a problem where we have unwanted permanent redirects on a Magento store we're working on, and I'm looking to see how we can start with a blank slate in terms of these redirects. We do not need any since it's a developing site, and we wouldn't want anything redirected within this domain, either. The store is not live, and the following is what happened.

    We didn't know about the URL Rewrite Management option under System -> Config -> Catalog -> SEO, so it was marked as "Yes" for "Create permanent redirects..." Some products were uploaded via a feed, but they were uploaded incorrectly. So, we re-uploaded them to over write. The result was that "White Shirt A" has its URL key as "white-shirt-a.html" in the admin or exported data feed, but the actual link that bring up the product is "white-shirt-a-1.html." If we go to "white-shirt-a.html," it gives us a 404 Not Found.

    How do we clear all these permanent redirects? We've tried disabling or deleting these specific request path and target path entries under Catalog -> URL Rewrite Mangement, but they don't have any effect.

  • laketuna
    laketuna almost 12 years
    about the core_url_rewrite, we have a guy who is helping us with Magento programming, and he told us we shouldn't delete anything in core_.... Prior to this post, I had asked him about truncating it, and he was very hesitant. Will truncating this table only affect the redirects that have been made into place without affecting anything else? We simply want our product URLs to be the cleaned up version of their names, as in that 'White Shirt A" example.
  • Gaurav Tewari
    Gaurav Tewari almost 12 years
    No, Truncating core_url_rewrite table doesn't have any effect on other features than url rewrites(REDIRECT). Do Catalog Url Indexing After it to create fresh new (clean) URL's in core_url_rewrite table
  • Gaurav Tewari
    Gaurav Tewari almost 12 years
  • laketuna
    laketuna almost 12 years
    Thanks for the link! Another question for you. Before emptying the rewrite table, we have System -> Configuration -> Catalog -> Catalog -> SEO -> "Create Permanent Redirect for URLs if URL Key Changed" as NO. Do you know why the "URL key" value of a product from the admin is still not the actual URL of this product even after reindexing the rewrite and clearing cache? Is it because they're permanent and the information in DB won't be changed unless we empty it? We tried deleting one row from core_ul_rewrite, and it does seem to fix it.
  • Gaurav Tewari
    Gaurav Tewari almost 12 years
    Yes these URL's are system created urls and after indexing Custom URL's are created which are used in website directly. Hope this will fix your problem with Catalog Rewrites.
  • laketuna
    laketuna almost 12 years
    one last question for you. Do you know URl rewrite entries in core_url_rewrite does not get removed even when the corresponding product has been removed from the Magento admin?
  • Gaurav Tewari
    Gaurav Tewari almost 12 years
    When you delete a product catalog url rewrites for that product will be removed from core_url_rewrite table. If there is some issue with catalog urls try to do Catalog Url Indexing to fix all urls.