Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: how to remove all permanent redirects

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.

like image 205
musicliftsme Avatar asked Jul 26 '12 16:07

musicliftsme


2 Answers

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.

like image 101
Gaurav Tewari Avatar answered Nov 05 '22 16:11

Gaurav Tewari


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.

like image 27
Marcin Klauza Avatar answered Nov 05 '22 14:11

Marcin Klauza