You are here:  » Help with mod_rewrite Filter by brand

Support Forum



Help with mod_rewrite Filter by brand

Submitted by carmela on Sat, 2007-12-15 18:34 in

Hi i'm Italian so i can't speak English well, I need help to modify the url after i apply the Filter by brand as I have seen in this thread : http://www.pricetapestry.com/node/212.

I have url like this:

http://www.example.com/category/example/?brandFilter=example

and I'd like to have urle like this:

http://www.example.com/category/example/example.htm

can you help me????

Thanks for all...

I love this script...

Submitted by support on Sat, 2007-12-15 18:46

Hi,

In your .htaccess you will see the following rules for the category rewrites:

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

Try changing this to:

RewriteRule ^category/$ categories.php
RewriteRule ^category/(.*)/$ search.php?q=category:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^category/(.*)/([0-9]*).html$ search.php?q=category:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^category/(.*)/(.*).html$ search.php?q=category:$1:&brandFilter=$2&rewrite=1%{QUERY_STRING} [L]

Using the URL format you want probably restricts you to the first page of results (which may be enough for what you want to do)

The other thing you need to do, because you cannot submit a FORM to this style of URL, you need to add a redirect at the top of search.php, so look for the following code:

$rewrite = isset($_GET["rewrite"]);

...and ADD the following code immediately afterwards:

  if ($_GET["brandFilter"] && !$rewrite)
  {
    $parts = explode($q);
    $url = $config_baseHREF."/".$parts[0]."/".$parts[1]."/".$_GET["brandFilter"].".html";
    header("Location: ".$url);
    exit();
  }

That should get you close...

Cheers,
David.

Submitted by carmela on Sat, 2007-12-15 20:40

Thanks David, it works perfectly but i'd like to change two things:

1 - when i have a brand of two words the url is:

http://www.example.com/category/example/example+example.htm

and if i trasform it in

http://www.example.com/category/example/example-example.htm

useing tapestry_hyphenate i have no resoults.

2 - I'd like to have the rewritten URL also in the other page...

can you help me??

Thanks thanks thanks

Carmela

Submitted by support on Sat, 2007-12-15 20:48

Hi Carmela,

If you use tapestry_hyphenate(), you will need to add a transposing modification in search.php using tapestry_normalise() (just as happens to the query value). From the other thread (www.pricetapestry.com/node/212) you added this code:

        if ($_GET["brandFilter"])
        {
          $where .= "AND brand='".database_safe($_GET["brandFilter"])."' ";
        }

You will need to change this as follows:

        if ($_GET["brandFilter"])
        {
          $_GET["brandFilter"] = tapestry_normalise($_GET["brandFilter"]);
          $where .= "AND brand='".database_safe($_GET["brandFilter"])."' ";
        }

That should do the trick!

What other URLs did you want to have rewritten URLs? I'm not quite sure what you mean in Q.2....

Cheers,
David.

Submitted by carmela on Sat, 2007-12-15 21:07

Thanks David but i have a problem:

When I apply filter by brend and I try to order the resoluts by "Product Rating" or "Low to High" or "High to Low"

I have this error:

Warning: Wrong parameter count for explode() in /search.php on line 14

Can you solve the problem???

Submitted by support on Sat, 2007-12-15 21:14

Hi,

Sorry - it should be:

    $parts = explode(":",$q);

...however the follow on links (like changing sort order) need to resort back to the non re-written URLs so the modified section will need to be changed, and without being able to test it, I think the following should work (including the above fix):

  if ($_GET["brandFilter"] && !$rewrite && !isset($_GET["sort") && !isset($_GET["page"]))
  {
    $parts = explode(":",$q);
    $url = $config_baseHREF."/".$parts[0]."/".$parts[1]."/".$_GET["brandFilter"].".html";
    header("Location: ".$url);
    exit();
  }

Hope this helps,
Cheers,
David.

Submitted by carmela on Sun, 2007-12-16 18:33

Hi David, thanks for all the help,

I still have a problem:

after i filter by brend and i use the mod_rewrite, only the first page of resoults has a good URL, the URLS of other page (page 2, 3 , 4...) are not mod rewrite...

can you help me?

Submitted by support on Mon, 2007-12-17 20:09

Hi Carmela,

Sorry for the delay in getting back to you on this. I think a more complex rewrite rule is going to be necessary to support having the follow on links re-written as well. Can you email me a direct link to one of the existing pages where the follow on links are not re-written and i'll take a look... Reply to your reg code or forum registration email is the quickest way to get me...

Cheers,
David.

Submitted by Leo on Thu, 2008-05-29 18:53

Hi David,

About the mod rewrite for the brandFilter i have try the last days to get this working to but not one solution has workt. Can you pls help me?

I have try maney times this tread http://www.pricetapestry.com/node/212 to get this working.
http://www.example.com/category/example/?brandFilter=example
I have done all the test about 5-10 times from all the treads i could find about this.
This is what i got

My normal searchresults are so when i click on a category.
http://www.mydomain/category/somecatname/
than on next page i get.
http://www.mydomain/category/somecatname/2.html
Works always perfect.

This is what i get with the brandFilter

http://www.mydomain/category/somecatname/somebrandname.html
When i click on the next page i get this.
http://www.mydomain/category/somecatname/2.html?brandFilter=somebrandname.html
Looks good but when you click on it it just give the normal second page (as without the brandfilter) and than it's not working anymore. The urls in the navigation links are normal again to then.
I changed the htaccess to the orginal without luck to.

I have try another code (under) than i get the nice urls when i click on it in the url from the browser only the page is not changing just the url.

if ($parts[0] == "category")
{
  print "Filter by Brand: ";
  $sql = "SELECT DISTINCT brand FROM `".$config_databaseTablePrefix."products` WHERE category = '".database_safe($parts[1])."'";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
if ($rewrite)
      {
        $brandHREF = "?brandFilter=".urlencode($row["brand"]);
      }
      else
      {
      $brandHREF = $config_baseHREF."search.php?q=".urlencode($q)."&brandFilter=".urlencode($row["brand"]);
}
      print "<a href='".$brandHREF."'>".$row["brand"]."</a> |";
    }
  }
}

Sorry for the long explanation but it seems by other people that it work i can not understand why not by me.
Do you have any idea why it is not working?

Leo

Submitted by support on Fri, 2008-05-30 08:04

Hello Leo,

The easiest thing to do is if you can email me your search.php and I will check the changes for you...

Cheers,
David.

Submitted by Leo on Wed, 2008-06-04 17:45

David

Any update on this yet?

Submitted by support on Wed, 2008-06-04 18:12

Hello Leo,

My apologies - I don't have an open email on this so i'll check back...

Cheers,
David.

Submitted by support on Wed, 2008-06-04 18:15

Sorry Leo,

I don't seem to have the last email on this - could you please send search.php again and I'll take a look.

If possible, can you .zip the file, otherwise my email program tries to display it inline instead of as an attachment...

Cheers,
David.