Magento Forum

   
Characters replacement in category or product url
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

Hi Magento team,

Until now, url rewriting uses the category (or product) name to make the URL key (if not specified by user).
Doing this, it replaces special characters (different from letters or numbers) with ‘-’.
With this, if my category name contains accents, they will be replaced by ‘-’.
I’ll be loosing SEO because my product name is not correct any longer.
What about doing something like:

public function formatUrlKey($str)
    
{
      $urlKey 
strtr(utf8_decode($str), utf8_decode('ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç'), 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc');
      
$urlKey preg_replace('#[^0-9a-z]+#i''-'$urlKey);
        
$urlKey strtolower($urlKey);
        
$urlKey trim($urlKey'-');

        return 
$urlKey;
    
}

I may have forgotten some special characters.
But with this, my category “Téléviseurs” will have a URL key: “televiseurs” instead of “t-l-viseurs”.
Much more SEO compliant, no ? smile

Thanks.

Edit:
it should be done in every formatUrlKey() method. Category, product, ...

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

We are experimenting with this method:

public function removeAccents($string$german=false)
    
{
        
// Single letters
        
$single_fr explode(" ""À Á Â Ã Ä Å Ą Ă Ç Ć Č Ď Đ Ð È É Ê Ë Ę Ě Ğ Ì Í Î Ï İ Ł Ľ Ĺ Ñ Ń Ň Ò Ó Ô Õ Ö Ø Ő Ŕ Ř Š Ś Ş Ť Ţ Ù Ú Û Ü Ů Ű Ý Ž Ź Ż à á â ã ä å ą ă ç ć č ď đ è é ê ë ę ě ğ ì í î ï ı ł ľ ĺ ñ ń ň ð ò ó ô õ ö ø ő ŕ ř ś š ş ť ţ ù ú û ü ů ű ý ÿ ž ź ż");
        
$single_to explode(" ""A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z");
        
$single = array();
        for (
$i=0$i<count($single_fr); $i++) {
            $single[$single_fr[$i]] 
$single_to[$i];
        
}
        
// Ligatures
        
$ligatures = array("Æ"=>"Ae""æ"=>"ae""Œ"=>"Oe""œ"=>"oe""ß"=>"ss");
        
// German umlauts
        
$umlauts = array("Ä"=>"Ae""ä"=>"ae""Ö"=>"Oe""ö"=>"oe""Ü"=>"Ue""ü"=>"ue");
        
// Replace
        
$replacements array_merge($single$ligatures);
        if (
$german{
            $replacements 
array_merge($replacements$umlauts);
        
}
        $string 
strtr($string$replacements);
        return 
$string;
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

It looks much better than my solution smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

Hi Moshe,

Sorry for digging out this smile

This hasn’t been used in Mage_Catalog_Model_Product_Url ?
I see it only in Mage_Catalog_Model_Category.

 
Magento Community Magento Community
Magento Community
Magento Community
 
redb
Jr. Member
 
Avatar
Total Posts:  23
Joined:  2008-02-15
Savoie, France
 

Sorry for this message is obsolete, the function perfectly work you can delete it !

Hi

By the way, what is the good solution ? In what file.
I’m beginning to use magento, it’s a pure “bonheur”
Thanks for this work

regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
eepsylon
Jr. Member
 
Total Posts:  3
Joined:  2010-10-21
 

Is there any way yet to get the correct url translation for products? eg. l’oréal -> l-oreal instead of l-or-al?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top