Magento: how to remove all permanent redirects
Asked Answered
C

4

8

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.

Cacka answered 26/7, 2012 at 16:3 Comment(0)
E
10

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.

Ernst answered 26/7, 2012 at 16:28 Comment(7)
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.Cacka
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 tableErnst
See Here: youtube.com/watch?v=8xttr_ILd6A&feature=player_embedded Fixing weird URL Rewrites yireo.com/tutorials/magento/magento-administration/…Ernst
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.Cacka
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.Ernst
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?Cacka
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.Ernst
L
1

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.

Listless answered 29/2, 2016 at 23:16 Comment(1)
Custom Product Urls is now a dead link. Do you know of an alternative?Alemanni
L
0

I do not guarantee that this is safe. But so far it seems to have worked.

I have run this query:

"DELETE * FROM core_url_rewrite WHERE is_system != 1";

That query removed all custom rewrite rules, of which we had something like 500,000. Most of those were created when someone turned off the ".html" extension in Search Engines Optimization without changing "Create Rewrite Rules When Urls are Changed" to "No".

Leverhulme answered 25/11, 2014 at 7:39 Comment(0)
A
0

On MAGENTO 2.4.6

On Magento 2, the table is now named url_rewrite.  Additionally, there is a table named catalog_url_rewrite_product_category that could possibly have some records pointing back to the url_rewrite table.

The url_rewrite table has a column named redirect_type. This column is set to 301 in the row to indicate a permanent redirection to the target_path column.

First, migrate catalog_url_rewrite_product_category.url_rewrite_ids. Below will give you the list of ids to migrate.

SELECT f.url_rewrite_id AS 'from id', t.url_rewrite_id AS 'to id' 
FROM url_rewrite f
JOIN url_rewrite t ON f.target_path = t.request_path
WHERE f.redirect_type = '301';

Then you can (recklessly) proceed with

DELETE FROM url_rewrite WHERE redirect_type = '301';
Alemanni answered 2/7 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.