Jump to content

Remove category ID in menu and redirect - how?


j_dk

Recommended Posts

Hi all.

I have used this thread: http://www.prestashop.com/forums/viewthread/12632 and it is now (almost) working. But, the big question is: how do i remove the category-id in my menu/tree-branch?

Then i also have a duplicate content problem. Both /ID-Category and /Category are avaliable. Is it possible to redirect /ID-Category to /Category - i have tried in htaccess but nothing works, it will just loop and then generate an error.

Really, really hope there is one to answer me this time in this forum.

Link to comment
Share on other sites

If you have modified your .htaccess file to remove IDs from links, you need to also modify classes/Link.php and remove the ID from the getCategoryLink function. Change line 53 from:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.intval($id_category->id).'-'.$id_category->link_rewrite) : 



to:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__/*.intval($id_category->id).'-'*/.$id_category->link_rewrite) : 



and line 56 from:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.intval($id_category).'-'.$alias) :



to:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__/*.intval($id_category).'-'*/.$alias) :

Link to comment
Share on other sites

If you have modified your .htaccess file to remove IDs from links, you need to also modify classes/Link.php and remove the ID from the getCategoryLink function. Change line 53 from:

... ...


Thank you so much, now it is working in the navigation! Do you then know, how to redirect the old /ID-category to /category (so we not are being punished for duplicate content).

Have tried in the htaccess with different methods, but non of them are working - normally i just got at "loop" error.
Link to comment
Share on other sites

Unfortunately, I don't know how to do that.


Okay, but thanks a lot. I then got one other question you maybe can help me with.

Right now my product-page link are: /category/ID-name.html. Is it possible to get it like: /category/ID-manufacturer-name.html?

This will be a lot better for us.
Link to comment
Share on other sites

I don't understand why you'd want to do that, since you'd end up with a lot of URLs that are the same, except for the product ID. Anyway, it would be difficult to do. You can change line 41 from:

return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.



to:

return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.Tools::link_rewrite($id_product->manufacturer_name).($id_product->ean13 ? '-'.



but this will only work when the getProductLink() function is called with an object. If it is called with the values as parameters, it won't work. You'd need to search for every instance of getProductLink() in your site and where it isn't called using an object, and pass in $product->manufacturer_name instead of $product->link_rewrite.

Link to comment
Share on other sites

I don't understand why you'd want to do that, since you'd end up with a lot of URLs that are the same, except for the product ID. Anyway, it would be difficult to do. You can change line 41 from:

return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.



to:

return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.Tools::link_rewrite($id_product->manufacturer_name).($id_product->ean13 ? '-'.



but this will only work when the getProductLink() function is called with an object. If it is called with the values as parameters, it won't work. You'd need to search for every instance of getProductLink() in your site and where it isn't called using an object, and pass in $product->manufacturer_name instead of $product->link_rewrite.



That is not working, but i will not get duplicate urls. For example i would like to rename /toy-cars/67-f430.html to /toy-cars/67-ferrari-f430.html.

The word ferrari being displayed on the shop now, but not in the url, because that is the manufacture (and not product name).

Really hope there is a solution for this.
Link to comment
Share on other sites

I misunderstood. In that case, you should change the code to the following:

return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.Tools::link_rewrite($id_product->manufacturer_name).'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.



And change everywhere that the function is called so the second parameter is:

Tools::link_rewrite($product->manufacturer_name).'-'.$product->link_rewrite

Link to comment
Share on other sites

I misunderstood. In that case, you should change the code to the following:

return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.Tools::link_rewrite($id_product->manufacturer_name).'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.



And change everywhere that the function is called so the second parameter is:

Tools::link_rewrite($product->manufacturer_name).'-'.$product->link_rewrite



I have changed the first thing in my link.php file.

But on the site, the links are not correct. I can see that the product-links are href="{$product.link|escape:'htmlall':'UTF-8'}", but how do it change that parameter so the manufacturer_name are in the product.link?

Could not find you second change/parameter in my files?
Link to comment
Share on other sites

I had a rethink and I think I've come up with a solution. Change the getProductLink() function in classes/Link.php to:

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL)
{    
   global $cookie;

   if (!isset($this->allow)) $this->allow = 0;

   if (!is_object($id_product))
       $id_product = new Product(intval($id_product), true, intval($cookie->id_lang));

   if (is_object($id_product))
       return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($id_product->category != 'home' AND !empty($id_product->category)) ? $id_product->category.'/' : '').intval($id_product->id).'-'.($id_product->manufacturer_name ? Tools::link_rewrite($id_product->manufacturer_name).'-' : '').$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') :
       (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product->id));
   elseif ($alias)
   {            
       return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.(($category AND $category != 'home') ? ($category.'/') : '').intval($id_product).'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') :
       (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product));
   }
   else
       return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product);
}

Link to comment
Share on other sites

If you are worried about duplicate URLs, I suggest buying the Duplicate URL Redirect module. I use it on my site. There is a section that checks where an older URL is being used and then redirects using "Move Permanently". You could modify the $proper_url variable to add the manufacturer name, and then the older URLs should redirect to the new ones.

Link to comment
Share on other sites

If you are worried about duplicate URLs, I suggest buying the Duplicate URL Redirect module. I use it on my site. There is a section that checks where an older URL is being used and then redirects using "Move Permanently". You could modify the $proper_url variable to add the manufacturer name, and then the older URLs should redirect to the new ones.


Sorry, but this was not working :'(

I have tried to install the module, but then it is just redirecting my new links /category to /id-category, and /id-manufacturer-product_title to /id-product_title and that is not good!

Hope someone can help me with this (redirect the old /id-category to /category).
Link to comment
Share on other sites

Try changing line 135 of modules/duplicateurlredirect/duplicateurlredirect.php from:

$proper_url = __PS_BASE_URI__.$lang.$dur_category->id_category."-".$dur_category->link_rewrite[$cookie->id_lang];



to:

$proper_url = __PS_BASE_URI__.$lang.$dur_category->link_rewrite[$cookie->id_lang];



and line 141 from:

$redirect_url = $protocol_link.$server_host.__PS_BASE_URI__.$lang.$dur_category->id_category."-".$dur_category->link_rewrite[$cookie->id_lang].($url_arr[1]?"?".$url_arr[1]:"");



to:

$redirect_url = $protocol_link.$server_host.__PS_BASE_URI__.$lang.$dur_category->link_rewrite[$cookie->id_lang].($url_arr[1]?"?".$url_arr[1]:"");

Link to comment
Share on other sites

Try changing line 135 of modules/duplicateurlredirect/duplicateurlredirect.php from ... ... ...


Thanks. But what about my manufacturer pages: shopname.com/manufacturer and my product pages: shopname.com/ID-manufacturer-product_name.

This two are redirecting to shopname.com/ID-manufacturer and shopname.com/ID-product_name :(
Link to comment
Share on other sites

You need to do a similar thing with the product and manufacturer redirects. Firstly, to make the manufacturer name accessible, change line 89 of modules/duplicateurlredirect/duplicateurlredirect.php from:

$dur_product = new Product($_REQUEST['id_product']);



to:

$dur_product = new Product($_REQUEST['id_product'], true);



then you can change line 108 from

$proper_url = __PS_BASE_URI__.$lang.($dur_category->link_rewrite[$cookie->id_lang]!="home"?$dur_category->link_rewrite[$cookie->id_lang]."/":"").$dur_product->id."-".$dur_product->link_rewrite[$cookie->id_lang];



to:

$proper_url = __PS_BASE_URI__.$lang.($dur_category->link_rewrite[$cookie->id_lang]!="home"?$dur_category->link_rewrite[$cookie->id_lang]."/":"").$dur_product->id."-".($dur_product->manufacturer_name ? Tools::link_rewrite($dur_product->manufacturer_name)."-":"").$dur_product->link_rewrite[$cookie->id_lang];



and line 114 from:

$redirect_url = $protocol_link.$server_host.__PS_BASE_URI__.$lang.($dur_category->link_rewrite[$cookie->id_lang]!="home"?$dur_category->link_rewrite[$cookie->id_lang]."/":"").$dur_product->id."-".$dur_product->link_rewrite[$cookie->id_lang].".html".($url_arr[1]?"?".$url_arr[1]:"");



to:

$redirect_url = $protocol_link.$server_host.__PS_BASE_URI__.$lang.($dur_category->link_rewrite[$cookie->id_lang]!="home"?$dur_category->link_rewrite[$cookie->id_lang]."/":"").$dur_product->id."-".($dur_product->manufacturer_name ? Tools::link_rewrite($dur_product->manufacturer_name)."-":"").$dur_product->link_rewrite[$cookie->id_lang].".html".($url_arr[1]?"?".$url_arr[1]:"");



and for the manufacturers, change line 162 from:

$proper_url = __PS_BASE_URI__.$lang.$dur_manufacturer->id_manufacturer."_".$dur_manufacturer->link_rewrite;



to:

$proper_url = __PS_BASE_URI__.$lang.$dur_manufacturer->link_rewrite;



and change line 168 from:

$redirect_url = $protocol_link.$server_host.__PS_BASE_URI__.$lang.$dur_manufacturer->id_manufacturer."_".$dur_manufacturer->link_rewrite.($url_arr[1]?"?".$url_arr[1]:"");



to:

$redirect_url = $protocol_link.$server_host.__PS_BASE_URI__.$lang.$dur_manufacturer->link_rewrite.($url_arr[1]?"?".$url_arr[1]:"");

Link to comment
Share on other sites

  • 8 months later...
If you have modified your .htaccess file to remove IDs from links, you need to also modify classes/Link.php and remove the ID from the getCategoryLink function. Change line 53 from:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.intval($id_category->id).'-'.$id_category->link_rewrite) : 



to:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__/*.intval($id_category->id).'-'*/.$id_category->link_rewrite) : 



and line 56 from:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.intval($id_category).'-'.$alias) :



to:

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__/*.intval($id_category).'-'*/.$alias) :



I follow the instruscyion above, but it gives me 500 Internal server error.
Any solution?
I'm working in my local server, not in any hosting yet.
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...