You are here:  » htaccess question (rewrite)

Support Forum



htaccess question (rewrite)

Submitted by Ch3W on Fri, 2008-10-31 00:42 in

Hi there,

Hope you're well! You previously helped me with adding categories to my search (I allow users to search by category). This changed the URL structure of for my price tapestry installation... which now means that re-write wont work if I enable it.

My current URL structure without re-write enabled in the config is the following:

Product Page:
http://www.mysite.co.uk/products.php?q=ProductName&category=CategoryName

when I enable use re-write in the config, the url structure changes to this:
Product Page:
http://www.mysite.co.uk/product/ProductName.html?category=CategoryName

Can you please help me have the following:
http://www.mysite.co.uk/product/categoryName/productName

Sorry mate, I'm not that great with regexp/htaccess. Thanks loads..

Matt

Submitted by support on Fri, 2008-10-31 10:31

Hi Matt,

2 things will have to be changed - both the URL structure and everywhere in the code that generates a link to a search engine friendly product URL. Firsly, the rewrite should be straight forward, simply replace:

RewriteRule ^product/(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]

with:

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

Then, to make search.php create the new URL, look for the following code around line 166:

        $searchresults["products"][$k]["productHREF"] = "product/".tapestry_hyphenate($product["name"]).".html";
        if ($rewrite) $searchresults["products"][$k]["productHREF"] = "../../".$searchresults["products"][$k]["productHREF"];

...and replace this with just:

        $searchresults["products"][$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($product["category"])."/".tapestry_hyphenate($product["name"]).".html";

Make exactly the same modification in products.php where you will find the same code at line 87, and finally in reviews.php look for the following code at line 47:

$rows[$k]["productHREF"] = "../product/".tapestry_hyphenate($row["name"]).".html";

...and replace this with:

$rows[$k]["productHREF"] = $config_baseHREF."product/".tapestry_hyphenate($row["category"])."/".tapestry_hyphenate($row["name"]).".html";

Cheers,
David.

Submitted by redspan on Sat, 2008-11-08 09:17

Hi David,

Are you absolutely certain about the code above? I configured it and it seemed to work, but without further changes I now find that the products aren't found. Instead, when I click on a merchant the product page appears containing the products, but when I click on any product to see the full description the status bar says it's not there

Price search results for Womens JewelleryRuby and Diamond Butterfly Brooch (product not found)

and the page displays some similar sounding products.

Regards,
Ben

Submitted by support on Sat, 2008-11-08 09:21

Hi Ben,

Could you email me the modified files and i'll check them out for you!

Cheers,
David.

Submitted by redspan on Sun, 2008-11-09 07:44

Hi David,

Files sent.

Thank you.

Regards,
Ben