You are here:  » Category/brand url


Category/brand url

Submitted by marco on Thu, 2015-01-08 10:15 in

Hello,

I have added a "/category/brand/" url in htacces like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/$ search.php?q=category:$1:&brandFilter=$2&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^(.*)/(.*)/(.*).html$ search.php?q=category:$1:&brandFilter=$2&page=$3&rewrite=1&%{QUERY_STRING} [L]

This works, except when the brand consists of more than one word.
for example: /shoes/tommy-hilfiger/

Searchresults displays a "-" in between the words of the brand in the title (and no products are shown).

If i change the "-" in a "+" in the url the results are shown.

How to make this work with the "-" in url?

Best,
Marco

Submitted by support on Thu, 2015-01-08 11:08

Hi Marco,

Filter values aren't normalised prior to search so the "-" remain but you can get the same results using the query category:Category-Name:brand:Brand-Name - have a go with:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/$ search.php?q=category:$1:brand:$2&rewrite=1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*).html$ search.php?q=category:$1:brand:$2&page=$3&rewrite=1&%{QUERY_STRING} [L]

I've included a second instance of the RewriteCond lines, as these only apply to the next RewriteRule immediately following...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco on Thu, 2015-01-08 13:15

Thanks!

Submitted by sirmanu on Wed, 2019-01-02 10:09

Hi!

This looks pretty neat for SEO purposes. I want to implement it in 15/09A , but I am a bit lost about how to achieve that.
My site have category hierarchy enabled, so I have a structure like the following URI:

example.com/cat/electronic/tablets

And If some user selects brand Apple, I want to have example.com/cat/electronic/tablets/apple.

How can I get that pretty URL when the user clicks on the search filters?

Submitted by support on Wed, 2019-01-02 15:50

Hi,

It's normally easiest in this case to get the rewrite working as you would like and then to look at the redirection (the filter form submits to search.php so it would need to determine from the filter parameters that it is OK to redirect i.e. no other filters in effect.

Ideally, there needs to be demarcation between the category and brand part for example by using the format;

example.com/category/Electronics/Tablets/brand/Apple/

(making sure the format ends in "/" means that the pagination can work nicely with 2.html, 3.html etc. appended as normal).

To try this in the first instance, if you edit your .htaccess and insert the following rules _before_ the existing category rules (otherwise they would override)

RewriteRule ^category/(.*)/brand/(.*)/$ search.php?q=category:$1:&brandFilter=$2&rewrite=1&%{QUERY_STRING} [L,B]
RewriteRule ^category/(.*)/brand/(.*)/(.*).html$ search.php?q=category:$1:&brandFilter=$2&page=$3&rewrite=1&%{QUERY_STRING} [L,B]

In addition, edit search.php and look for the following code at line 18:

  $brandFilter = (isset($_GET["brandFilter"])?$_GET["brandFilter"]:"");

...and REPLACE with:

  $brandFilter = (isset($_GET["brandFilter"])?tapestry_normalise($_GET["brandFilter"]):"");

With that in place, browse to a /category/ results page, and then append brand/Existing-Brand/ to the URL and the results should be shown with the clean URL and filtered...

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Wed, 2019-01-02 17:08

Ok David, that is working.
I only need to compare with lower case at searchfilters.php because I have some filters for capital letter.

$selected = (strtolower ($brandFilter)==strtolower ($row["brand"])?"selected='selected'":"");

The redirection is okey.

?q=category:electronics/tablets/:&merchantFilter=&brandFilter=apple&minPrice=&maxPrice=

This is URL decoded. I don't know why are three dots before &merchantFilter

Submitted by support on Thu, 2019-01-03 10:03

Hi,

The : comes from the query constructed for the index searches e.g. category:/path/to/category/:

To apply the redirect, edit search.php and look for the following code at line 105:

          $nodeInfo = tapestry_categoryHierarchyNodeInfo($parts[1]);

...and REPLACE with:

          if ((!$rewrite) && ($page==1) && ($brandFilter) && ($merchantFilter.$categoryFilter.$minPrice.$maxPrice===""))
          {
            header("Location: ".tapestry_indexHREF("category",$parts[1])."brand/".tapestry_hyphenate($brandFilter)."/");
            exit();
          }
          $nodeInfo = tapestry_categoryHierarchyNodeInfo($parts[1]);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Thu, 2019-01-03 20:20

Thanks David. It works perfectly.

Submitted by sirmanu on Tue, 2019-01-08 16:02

This starts to be interesting!

From other thread, I have the ability to add custom description to be displayed under
example.com/cat/electronic/tablets/. (I have a column description at pt_categories_hierarchy).

Is any chance I can have a different text depending on the brand selected?

For instance, if the user selects apple: example.com/cat/electronic/tablets/brand/apple.

Thank you!

Submitted by support on Wed, 2019-01-09 08:52

Sure,

If you haven't done so already, apply the mods to add description field to Brand Mapping (described in this comment) and then where you are displaying the description from Category Hierarchy Mapping, add for example:

  if ($rewrite && $brandFilter)
  {
    $sql = "SELECT description FROM `".$config_databaseTablePrefix."brands` WHERE name='".database_safe($brandFilter)."' AND description <> ''";
    if (database_querySelect($sql,$rows))
    {
      print "<p>".$rows[0]["description"]."</p>";
    }
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Wed, 2019-01-09 18:10

The problem with that approach is for example, if I have the brand Apple, the description should be different for tablets or mobiles phones.
How can I achieve that?

Submitted by support on Thu, 2019-01-10 11:17

Hi,

What you could do is simply create a directory hierarchy (relative to Price Tapestry installation folder) that exactly matches that displayed in the URL, containing a file "info.html". For example, for

http://www.example.com/category/Portable-Electronics/Tablets/brand/Apple/

Create the file:

category/Portable-Electronics/Tablets/brand/Apple/info.html

And then in your code, use:

  if ($rewrite && $brandFilter)
  {
    $path = str_replace($config_baseHREF,"",$_SERVER["REQUEST_URI"]);
    $filename = $path."info.html";
    if (file_exists($filename))
    {
      require($filename);
    }
  }

...and the contents of info.html will be included into the page.

Cheers,
David.
--
PriceTapestry.com