You are here:  » SEO friendly search urls - can category and keword be combined?

Support Forum



SEO friendly search urls - can category and keword be combined?

Submitted by bingobongo on Fri, 2010-05-21 14:20 in

Hi David,

Firstly congrats on such a great product. It's so customisable - i'm using it to build on niche sections in an already large price comparison website - kudos!

Secondly, i've a bit of an issue. I followed your tutorial to turn ampersand filled urls into nice static ones.

At the moment when I do a search, the url looks like /search/relevance/blackberry/ which works fine.

I do, however, want to create links to certain keywords AND categories like /search/relevance/blackberry:category:prepay-mobile-phones/

In the string above, 'blackberry' is the keyword, and the category name is 'Prepay Mobile Phones'.

However, the query above is showing results from other categories also - what do you recommend the format be for such a query?

Thanks again for such a great product!

Submitted by support on Fri, 2010-05-21 14:46

Hi,

Can you email me your search.php and I'll modify the merchant/category/brand search handler to support multiple fields including keywords (a search on the name field), and you will then be able to link to, for example:

/search/relevance/category:prepay-mobile-phones:name:blackberry/

Cheers,
David.

Submitted by bingobongo on Fri, 2010-05-21 15:09

Thanks for your reply to this - it's in your mailbox as we speak ;-)

Submitted by stevewales20 on Mon, 2010-05-24 20:23

Is it possible to provide the changes made so others can follow? I feel that people don't learn things unless they get to do it themselves through time and testing :)

If you can give me a pointer. It would be appreciated. I was going to do htaccess rewrites but it would be time consuming, being able to use categories would be excellent.

Thanks
Steve

Submitted by support on Tue, 2010-05-25 08:40

Hi Steve,

Sure - firstly, the new rule should be added to the end of .htaccess

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

Next, a hidden field needs to be added to the search form to trigger the redirect. To do this, in html/searchform.php, search for the following:

</form>

...and REPLACE with:

<input type='hidden' name='redir' value='1' /></form>

Then in search.php, look for the following code at line 12:

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

...and REPLACE with:

  $rewrite = isset($_GET["rewrite"]);
  if ($_GET["redir"])
  {
     $location = $config_baseHREF."search/".$sort."/".tapestry_hyphenate($q)."/";
     header("Location: ".$location);
     exit();
  }

Finally, to make sure that the change sort order links go to the rewritten version, look for the following block of code beginning at line 229:

      $sortHREF = $config_baseHREF."search.php?q=".urlencode($q)."&amp;page=1&amp;";
      if ($minPrice || $maxPrice)
      {
        $sortHREF .= "minPrice=".$minPrice."&amp;maxPrice=".$maxPrice."&amp;";
      }
      $sortHREF .= "sort=";
      $sortRelevance = ($sort=="relevance"?"<strong>".translate("Relevance")."</strong>":"<a href='".$sortHREF."relevance'>".translate("Relevance")."</a>");
      if ($config_useInteraction)
      {
        $sortRating = ", ".($sort=="rating"?"<strong>".translate("Product Rating")."</strong>":"<a href='".$sortHREF."rating'>".translate("Product Rating")."</a>");
      }
      else
      {
        $sortRating = "";
      }
      $sortPriceAsc = ($sort=="priceAsc"?"<strong>".translate("Low to High")."</strong>":"<a href='".$sortHREF."priceAsc'>".translate("Low to High")."</a>");
      $sortPriceDesc = ($sort=="priceDesc"?"<strong>".translate("High to Low")."</strong>":"<a href='".$sortHREF."priceDesc'>".translate("High to Low")."</a>");

...and REPLACE with:

      if ($rewrite)
      {
      $sortHREF = $config_baseHREF."search/%SORT%/".urlencode($q)."/";
      $sortRelevance = ($sort=="relevance"?"<strong>".translate("Relevance")."</strong>":"<a href='".str_replace("%SORT%","relevance",$sortHREF)."'>".translate("Relevance")."</a>");
      if ($config_useInteraction)
      {
        $sortRating = ", ".($sort=="rating"?"<strong>".translate("Product Rating")."</strong>":"<a href='".str_replace("%SORT%","rating",$sortHREF)."'>".translate("Product Rating")."</a>");
      }
      else
      {
        $sortRating = "";
      }
      $sortPriceAsc = ($sort=="priceAsc"?"<strong>".translate("Low to High")."</strong>":"<a href='".str_replace("%SORT%","priceAsc",$sortHREF)."'>".translate("Low to High")."</a>");
      $sortPriceDesc = ($sort=="priceDesc"?"<strong>".translate("High to Low")."</strong>":"<a href='".str_replace("%SORT%","priceDesc",$sortHREF)."'>".translate("High to Low")."</a>");
      }
      else
      {
      $sortHREF = $config_baseHREF."search.php?q=".urlencode($q)."&amp;page=1&amp;";
      if ($minPrice || $maxPrice)
      {
        $sortHREF .= "minPrice=".$minPrice."&amp;maxPrice=".$maxPrice."&amp;";
      }
      $sortHREF .= "sort=";
      $sortRelevance = ($sort=="relevance"?"<strong>".translate("Relevance")."</strong>":"<a href='".$sortHREF."relevance'>".translate("Relevance")."</a>");
      if ($config_useInteraction)
      {
        $sortRating = ", ".($sort=="rating"?"<strong>".translate("Product Rating")."</strong>":"<a href='".$sortHREF."rating'>".translate("Product Rating")."</a>");
      }
      else
      {
        $sortRating = "";
      }
      $sortPriceAsc = ($sort=="priceAsc"?"<strong>".translate("Low to High")."</strong>":"<a href='".$sortHREF."priceAsc'>".translate("Low to High")."</a>");
      $sortPriceDesc = ($sort=="priceDesc"?"<strong>".translate("High to Low")."</strong>":"<a href='".$sortHREF."priceDesc'>".translate("High to Low")."</a>");
      }

Hope this helps!

Cheers,
David.