Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 3
Reindexing “Catalog URL Rewrites” fails
 
oweneck
Jr. Member
 
Total Posts:  23
Joined:  2010-11-26
 

I am also getting the same error, if I comment out to catch the error or try and of the options or suggestions above it works but it only adds the records where the products are in the root directory, for example /product.html and not any of the others in any of the categories, such as /category/product.html or /category/subcategory/product.html.

The really weird thing is the numbers that are in the url_rewrite_id go up but the skip when there should have been an entry for the ones it won’t add, for example if the first product is in 5 categories it should be like:-
1 /product.html
2 /category/product.html
3 /category/product.html
4 /category/product.html
5 /category/product.html
6 /product2.html
But instead it does this:-
1 /product.html
6 /product2.html

Any help would be really appreciated, I am supposed to have this store available soon and I can’t go live with it until I’ve fixed this problem.

Edit: I have also tried truncating my core_url_rewrite table, I have installed magento from fresh, I have tried multiple methods of importing, I always index everything from the command line, nothing seems to be working.

 
Magento Community Magento Community
Magento Community
Magento Community
 
oweneck
Jr. Member
 
Total Posts:  23
Joined:  2010-11-26
 
steroyle - 10 November 2011 02:32 AM

hillzzz - 13 October 2011 01:58 PM
Then I had an idea I used phpmyadmin to truncate the core_url_rewrite table. Note I did not delete it I emptied the table that is I deleted all the rows but left the table structure intact.

Next I re-indexed from the command line again and it worked without errors. I tried re-indexing in the admin interface and again it worked without errors.

It appears to have fixed the problem

This worked perfectly for me on 1.6

I have tried this, I wish this would work for me too, it seems to be the problem as someone else stated before that when you’re trying to index a product that’s in multiple directories that are in the root directory of your site it fails, the best you can do is to get rid of the exceptions so it continues to index the url rewrites but it just skips over the ones with category data in them. I did try to do a fresh install with a fresh database and it seemed to work but I may be wrong, I will try it again properly later and see.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bendim
Jr. Member
 
Total Posts:  13
Joined:  2011-06-25
 
hillzzz - 13 October 2011 01:58 PM

I had the URL indexing Processing issue after upgrading from 1.4.01 to 1.6.
Then I had an idea I used phpmyadmin to truncate the core_url_rewrite table. Note I did not delete it I emptied the table that is I deleted all the rows but left the table structure intact.

Next I re-indexed from the command line again and it worked without errors. I tried re-indexing in the admin interface and again it worked without errors.

Awesome this worked!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
dakinibilyana
Jr. Member
 
Total Posts:  12
Joined:  2009-09-02
 

Hi All,
i have tried emptying the cache, truncating the core_url_rewrite table, it didn’t resolve my issue.
I followed the advice of twotools and it worked for me on magento v 1.6.1. reindex now worked and finished correctly.

thanks very much for your help.
dakini

 
Magento Community Magento Community
Magento Community
Magento Community
 
ckpepper02
Jr. Member
 
Total Posts:  3
Joined:  2011-06-16
 
Djay - 10 October 2011 03:34 AM


public function saveRewrite($rewriteData$rewrite)
{
    
....
        try 
{
            $adapter
->insert($this->getMainTable(), $rewriteData);
        
catch (Exception $e{
            Mage
::logException($e);
            
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
        
}
    }
    
unset($rewriteData);

    return 
$this;
}

A simple correction is to launch the exception only if the datas contains a valid category_id :

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData['category_id'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
    
}
}

or use the previous conditon from 1.4 (not tested).

Djay

Thanks Djay! This worked for me too.

You find this code in: /app/code/core/Mage/Catalog/Model/Resource/Url.php around line 232

 
Magento Community Magento Community
Magento Community
Magento Community
 
angelicakm
Jr. Member
 
Total Posts:  27
Joined:  2011-03-29
 

I have tried DJay\’s solution and got a 500 error when trying to reindex url rewrites.

I\’m using 1.6.2. magento and still looking for a solution for this bug

 
Magento Community Magento Community
Magento Community
Magento Community
 
AdeshSuryan
Jr. Member
 
Avatar
Total Posts:  10
Joined:  2011-02-25
Delhi
 

Hi Every one ,
Check the solution :

file path : app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Url.php

or

app/code/core/Mage/Catalog/Model/Resource/Url.php

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData[\'category_id\'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper(\'catalog\')->__(\'An error occurred while saving the URL rewrite\'));
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
mwestrik
Jr. Member
 
Total Posts:  15
Joined:  2010-05-14
 

For me this solution only produces error messages, so apparetly i’m copying the wrong lines.

The original code is:

try {
                $adapter
->insert($this->getMainTable(), $rewriteData);
            
catch (Exception $e{
                Mage
::logException($e);
                
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
            
}
        }
        
unset($rewriteData);

        return 
$this;
    
}

I tries replacing that with:

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData[\'category_id\'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper(\'catalog\')->__(\'An error occurred while saving the URL rewrite\'));
    
}

        }
        
unset($rewriteData);

        return 
$this;
    
}

but that only produces two errors.

You will understand i’m not a php programmer, i only know how to cut and paste. I do understand however, that when adding opening bracks (at the end of the “if” statement), one should add closing bracks as well. Point is: I don’t have a clue where.

Can anybody please explain me what to put in place of the given original code?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mwestrik
Jr. Member
 
Total Posts:  15
Joined:  2010-05-14
 

when changing the aboce code to

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData[\'category_id\'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper(\'catalog\')->__(\'An error occurred while saving the URL rewrite\'));
    
}
}
as Adesh Suryan says, I get the following error message:

Parse error: syntax error, unexpected T_PUBLIC in /home/XXXXXXXX/public_html/app/code/core/Mage/Catalog/Model/Resource/Url.php on line 299

Line 299 is this one:

public function saveRewriteHistory($rewriteData)
    
{
        $rewriteData 
= new Varien_Object($rewriteData);
        
// check if rewrite exists with save request_path
        
$rewrite $this->getRewriteByRequestPath($rewriteData->getRequestPath(), $rewriteData->getStoreId());
        if (
$rewrite === false{
            
// create permanent redirect
            
$this->_getWriteAdapter()->insert($this->getMainTable(), $rewriteData->getData());
        
}

        
return $this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
fr0x
Member
 
Total Posts:  59
Joined:  2009-05-20
 

Don’t copy Adesh’s code....it has extra slashes ( \ ) that are probably causing you issues, Djays solution is the same thing but that piece of code *does not* have those slashes in it.  The extra slashes probably got accidently added due to some auto-parsing of the code.

This is what it should look like:

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData['category_id'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
mwestrik
Jr. Member
 
Total Posts:  15
Joined:  2010-05-14
 

Hi fr0x, thanks for the comments. I was aware of those slashes though. Not by myself, but they generated some other error messages that I was capable of solvng myself.

Your solution however still generates the same error, so I guess I’m replacing too much or too little.

Do I have to replace this whole part:

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData[\'category_id\'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper(\'catalog\')->__(\'An error occurred while saving the URL rewrite\'));
    
}

        }
        
unset($rewriteData);

        return 
$this;
    
}

or do some lines need to remain there?

Btw, i’m running 1.6.1.0

Is it possible for someone to upload a working Url.php to save everybody some time?

 
Magento Community Magento Community
Magento Community
Magento Community
 
fr0x
Member
 
Total Posts:  59
Joined:  2009-05-20
 

You just want to replace the

try {
}
catch {
}

portion within

public function saveRewrite($rewriteData$rewrite)

Everything else within that function should remain the same.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mwestrik
Jr. Member
 
Total Posts:  15
Joined:  2010-05-14
 

Thanks, I dont get any error messages anymore.

However, one of my categories has one product in it. On the frontend, when opening that category, it says “no products available”, even though the category AND the product are enabled for this store and store view.

Can that be an indexing error caused by the problems before? If so, how can I solve that? I already tried removing the product from the category, saving it and putting it back in.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chabbu
Jr. Member
 
Total Posts:  2
Joined:  2011-10-18
 
fr0x - 18 April 2012 07:13 AM

Don’t copy Adesh’s code....it has extra slashes ( \ ) that are probably causing you issues, Djays solution is the same thing but that piece of code *does not* have those slashes in it.  The extra slashes probably got accidently added due to some auto-parsing of the code.

This is what it should look like:

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData['category_id'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
    
}
}

I too had errors after copying this code and figured out that I had to put an extra curly bracket at the end, so it should be:

try {
    $adapter
->insert($this->getMainTable(), $rewriteData);
catch (Exception $e{
    
// Bug - the category_id is set to null when the category has a level <= 1
    // So if our product is in 2 differents level 1 categories, the indexer crashes
    
if ($rewriteData['category_id'!= null{
        Mage
::logException($e);
        
Mage::throwException(Mage::helper('catalog')->__('An error occurred while saving the URL rewrite'));
    
}

}
 
Magento Community Magento Community
Magento Community
Magento Community
 
milali
Jr. Member
 
Total Posts:  26
Joined:  2012-01-08
 

Hi I have a local Lampp installation

with my live site duplicated on it, using the same url setup in the virtual host setup etc.

If use server rewrites is enabled. none of the navigation works....

if I disable it, all of the navigation works…

I have tried all the idea above and none of them worked :/

my lampp installation has mod rewrite module loaded.

ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 3