You are here:  » /category/brand/customfield url


/category/brand/customfield url

Submitted by zway on Mon, 2016-04-04 01:58 in

Hi David,

How would I achieve a URL structure like this for product pages?

I.e example.com/televisions/sony/customfield

Thanks

Submitted by support on Mon, 2016-04-04 09:18

Hi,

Sure - firstly, since not all fields are included in the search SELECT query, in search.php look for the following code at line 476;

    $sql2 = "SELECT id,name,normalised_name,image_url,description,price,rating FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

...and REPLACE with:

    $sql2 = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE id IN (".$in.")";

Then the product page URL can be constructed as required at line 66 in includes/tapestry.php:

    return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"])).".html";

So to include category, brand and customfield (using hyphen in place of empty values), use:

    $href = $config_baseHREF;
    $href .= ($product["category"]?urlencode(tapestry_hyphenate($product["category"])):"-")."/";
    $href .= ($product["brand"]?urlencode(tapestry_hyphenate($product["brand"])):"-")."/";
    $href .= ($product["customfield"]?tapestry_hyphenate(urlencode($product["customfield"])):"-")."/";
    $href .= urlencode(tapestry_hyphenate($product["normalised_name"])).".htm";
    return $href;

Finally, edit .htaccess and add at the very end of the file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/(.*).html$ products.php?q=$1&rewrite=4&%{QUERY_STRING} [B,L]

(rules not containing a known common base need to go last)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com