Remove category_id from product URL

Developer
Från United Kingdom
Medlem sedan okt. 2018

Hi Tim,

This add-on has been working well for me. It does however create duplicate links to the same product page.

For example a product can have multiple URLs if it exists in multiple categories:
https://www.abc.com/ducks
https://www.abc.com/ducks?category_id=20
https://www.abc.com/ducks?category_id=5

What I want is to remove the parameter "?category_id=#" overall so that a product will only have 1 URL (https://www.abc.com/ducks).

Please can you help?

Bishar

tim
Founder
Från Sweden
Medlem sedan maj 2013
tim

So ?category_id is used to refer to a location in the category tree other than default category.
You will no longer have a pleasant result viewing a product found in more than one category if we remove this.

Developer
Från United Kingdom
Medlem sedan okt. 2018

Hi Tim,

Well apart from the url containing the category_id and the breadcrumb showing the category name, the rest of the page is exactly the same. I don't really think I will miss much if we removed the category_id from the url.

Please can you guide me through it?

tim
Founder
Från Sweden
Medlem sedan maj 2013
tim

In vmods/permalinks.xml. Find the directive for url_product.inc.php:



    <operation method="after" type="multiline" onerror="warning">
      <find><![CDATA[
      if (empty($link->query['product_id'])) return;
      ]]></find>

      <insert><![CDATA[
      $permalinks_query = database::query(
        "select * from ". DB_TABLE_PREFIX ."permalinks
        where entity = 'product'
        and entity_id = ". (int)$link->query['product_id'] ."
        and language_code = '". database::input($language_code) ."'
        limit 1;"
      );

      if ($permalink = database::fetch($permalinks_query)) {
        $link->unset_query('product_id');
        $link->path = $permalink['permalink'];
        return $link;
      }
      ]]></insert>
    </operation>
  </file>```

After
$link->unset_query('product_id');

Add
$link->unset_query('category_id');
Developer
Från United Kingdom
Medlem sedan okt. 2018

Thank you Tim. That worked!

Du
Denna webbplats använder inga kakor och ingen spårningsteknik från tredje part . Vi tror att vi kan göra det bättre än andra och tänker verkligen på din integritet.