Jump to content

[Solved] Friendly Url - how to regenerate?


soluthier

Recommended Posts

thanks for information, im really glad that i could help you in this case :)

if you've got any other question related to this case - feel free to continue discussion below - [solved] isn't mean [closed] ;)

happy selling

Link to comment
Share on other sites

  • 4 years later...

I seriously don't understand why ppl (there are multiple forum posts on this) tell someone who wants to rebuild all URLs how to regenerate an htaccess file...

Or are those ppl just formulating their questions wrong? As most of the posts are marked as solved?

I mean if I was looking for this, I'd be speaking of the table column "link_rewrite" in the ps_product_lang table... So how to regenerate all those entries based on the products title/name it has? Like the same way when you click the "Generate" button under the SEO Tab on product edit page and then click on Save. Just for all products.

No single one really has found a solution for this? Guess I'll really have to write a script for this then^^

  • Like 1
Link to comment
Share on other sites

  • 10 months later...
  • 6 months later...
On 5/9/2018 at 4:47 PM, oliiix said:

I seriously don't understand why ppl (there are multiple forum posts on this) tell someone who wants to rebuild all URLs how to regenerate an htaccess file...

Or are those ppl just formulating their questions wrong? As most of the posts are marked as solved?

I mean if I was looking for this, I'd be speaking of the table column "link_rewrite" in the ps_product_lang table... So how to regenerate all those entries based on the products title/name it has? Like the same way when you click the "Generate" button under the SEO Tab on product edit page and then click on Save. Just for all products.

No single one really has found a solution for this? Guess I'll really have to write a script for this then^^

I am really looking for this.

Link to comment
Share on other sites

  • 4 months later...
En 9/5/2018 a las 2:17 PM, oliiix dijo:

I seriously don't understand why ppl (there are multiple forum posts on this) tell someone who wants to rebuild all URLs how to regenerate an htaccess file...

Or are those ppl just formulating their questions wrong? As most of the posts are marked as solved?

I mean if I was looking for this, I'd be speaking of the table column "link_rewrite" in the ps_product_lang table... So how to regenerate all those entries based on the products title/name it has? Like the same way when you click the "Generate" button under the SEO Tab on product edit page and then click on Save. Just for all products.

No single one really has found a solution for this? Guess I'll really have to write a script for this then^^

Exactly the same case here. Every time I clone a product I have to remember to go and press de REGENERATE button.

Plus, I have two languages, so when I upload a list of for example 1000 new products, the first time generates in both languages the same friendly-url. When I upload another list with the second language, all the products are translated but the friendly-url is still the same for both languages. I have to press the regenerate button for every single product. It's a waste of time if I have thousands of products! There's no solution?

Should I open a new post?

Link to comment
Share on other sites

  • 8 months later...
On 2/26/2020 at 8:21 PM, elshekar said:

Exactly the same case here. Every time I clone a product I have to remember to go and press de REGENERATE button.

Plus, I have two languages, so when I upload a list of for example 1000 new products, the first time generates in both languages the same friendly-url. When I upload another list with the second language, all the products are translated but the friendly-url is still the same for both languages. I have to press the regenerate button for every single product. It's a waste of time if I have thousands of products! There's no solution?

Should I open a new post?

Its a pitty that even after 2 years there is not "RIGHT" answer to this question.

I have exactly the same problem. I have a lot of products duplicated and users forget to click on the button Generate because it is in the another section when they duplicate product, it is not obvious on the first. So we REALLY do not need to regenerate .htaccess file it is nonsense in this case. We really need automatic generation of friendly URLs.

First I have to say that this is a big error of the prestashop 1.5. When user duplicate product then this MUST be generated automaticaly as a default. It should not be left on the user. Or at least it should be done as a checkbox but defaulty regenerate it.

Secondly I tried to rewrite it in the database as was noted here and it works. So the problem has very simple solution:

  1. if needed once a time, use update statement on the database for table ps_product_lang on column link_rewrite, the update statement may be a little long because there is not so simple to translate all accented chars to without accent but here is already created solutions (https://stackoverflow.com/questions/4813620/how-to-remove-accents-in-mysql 🙂 I have added the czech accents and minus sign and plus sign for the prestashop friendly URLs:

    UPDATE ps_product_lang SET ps_product_lang.link_rewrite = LOWER(ps_product_lang.name),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,' ','-'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'+',''),

    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'á','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ä','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'č','c'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ď','d'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'é','e'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ě','e'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'í','i'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ĺ','l'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ň','n'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ó','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ö','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ř','r'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'š','s'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ť','t'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ú','u'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ů','u'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ü','u'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ý','y'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ž','z'),

    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ð','Dj'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'À','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Á','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,' ','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ã','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ä','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Å','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Æ','A'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ç','C'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'È','E'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'É','E'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ê','E'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ë','E'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ì','I'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Í','I'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Î','I'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ï','I'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ñ','N'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ò','O'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ó','O'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ô','O'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Õ','O'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ö','O'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ø','O'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ù','U'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ú','U'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Û','U'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ü','U'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ð','Dj'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Þ','B'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ß','Ss'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'à','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'â','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ã','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ä','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'å','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'æ','a'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ç','c'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ê','e'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ë','e'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ì','i'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'î','i'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ï','i'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ð','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ñ','n'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ò','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ô','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'õ','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ö','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ø','o'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ù','u'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'û','u'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ý','y'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'þ','b'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ÿ','y'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ƒ','f'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'œ','oe'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'Ł','L'),
    ps_product_lang.link_rewrite = replace(ps_product_lang.link_rewrite,'ą','a'),
    ps_product_lang.link_rewrite = trim(ps_product_lang.link_rewrite)

    and you can add or delete the chars that you want
  2. add a button to mass functions for list of products (like there is already button to delete selected), this is very simple solutions and you can regenerate it to any selected products
  3. create module that can be very simple just one button to regenerate all proudcts or very complicated that that can regenerate products by category, selected, or any other what you can think
  4. fix the prestashop by yourself it is opensource, so generate friendly url for clonning of product

 

Edited by vlskrbek (see edit history)
Link to comment
Share on other sites

Of course. It's a pity that you did not write it 2 or 6 years ago. This answer was needed such a long time. 

And my answer was just a suggestion how to do it. You can use sql or php or anything else. 

But as I said thus php can be used for the button for bulk rewrite in the list of product. Simple and universal solution. 

Link to comment
Share on other sites

  • 5 months later...
On 11/19/2020 at 9:19 AM, Guest said:

Why such a lengthy solution ???

In Prestashop there is a function to create a rewrite URL (Tools::str2url).

Just write a small script (7 lines) and update all URLs by product name.

Just save the php script to the root of prestashop and call the URL of the script. (eg. https://my-shop.com/updateLinkRewrite.php)


<?php
    include_once ('./config/config.inc.php');
    $products = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'product_lang');
    foreach ($products as $product){
        Db::getInstance()->execute("UPDATE "._DB_PREFIX_."product_lang SET link_rewrire = '".Tools::str2url($product['name'])."' WHERE id_product = ".$product['id_product']." AND id_shop = ".$product['id_shop']." AND id_lang = ".$product['id_lang']);
    }
    echo 'done';

Of course, it would be good to have a unique product name, or add a reference number or EAN13, etc. after the product name ...

ahh, thank you!
But there is small mistyping in code link_rewrire

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...