You are here:  » .htaccess


.htaccess

Submitted by babyuniverse on Sat, 2016-01-30 10:32 in

Hi David,

Is it possible to use .htaccess to add a custom field to the product url.
I have removed the .html using anther mod so my product url looks like

http://example.com/product/adidas-Pants

I would like to add my custom field of colour to the trialing end like this
http://example.com/product/adidas-Pants-black

Thanks
Richard

Submitted by support on Sat, 2016-01-30 10:43

Hello Richard,

Ideally there needs to be a delimiter, or some method of absolutely differentiating the product name and the colour in the URL. One option would be brackets for example;

http://example.com/product/adidas-Pants-(black)

To give this a go, first the `colour` field needs to be added to the search result set re-query in search.php, so where you have 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.")";

...REPLACE with:

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

Next, edit includes/tapestry.php and look for the following code around line 66:

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

(above has .html removed as already modified)

...and REPLACE with:

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

And then as the RewriteRule in .htaccess:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Sun, 2016-02-14 03:29

How about adding

<?php
 
print $mainProduct["id"]; 
?>
to this url instead of colour?
product name - 123456

Im trying to create unique URL's from my datafeed

Submitted by support on Mon, 2016-02-15 09:16

Hi,

Sure - id is already selected so you can use in place of colour in the replacement to includes/tapestry.php eg:

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

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Sat, 2016-02-20 04:49

How do i remove the brackets for the ID, im assuuming I change .htaccess

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

Submitted by support on Sat, 2016-02-20 08:37

Hi Richard,

With the change to includes/tapestry.php as follows:

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

Have a go with the RewriteRule in .htaccess as follows:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Sat, 2016-02-20 09:13

How about adding merchant at the start of the url? This is based on the assumption that none of my feeds have multiple merchants.

This is workin, but the .htaccess part isnt working.

return $config_baseHREF."product/".tapestry_hyphenate($product["merchant"])."-".urlencode(tapestry_hyphenate($product["normalised_name"]))."-(".tapestry_hyphenate($product["id"]).")";

Submitted by support on Sat, 2016-02-20 09:48

Hi Richard,

If you separate the merchant from the product name by "/" that makes things much easier, and with the brackets removed as per the previous example, so using a includes/tapestry.php replacement of:

return $config_baseHREF."product/".tapestry_hyphenate($product["merchant"])."/".urlencode(tapestry_hyphenate($product["normalised_name"]))."-".tapestry_hyphenate($product["id"]);

And then in .htaccess

RewriteRule ^product/(.*)/(.*)-([0-9]*)$ products.php?q=$2&rewrite=1&%{QUERY_STRING} [B,L]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Sat, 2016-02-20 11:49

Thanks Mate, Seems to be working.

I just noticed that Page 2 of search results isnt working. .htaccess is below. Is it do to the removal of .html?

{code saved}

Submitted by support on Sun, 2016-02-21 11:02

Hi Richard,

It looks like the first search rule is missing, where you have added the following for re-written general queries;

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

Based on your other rules re-writing to search.php this should include the .html, but also the top level (page 1 rewrite) - have a go with;

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

Cheers,
David.
--
PriceTapestry.com

Submitted by babyuniverse on Tue, 2016-02-23 04:16

I think 1 of these changes has broken the sitemap.php

Have a look at {link saved} and you will see the xml is missing the siteid

Submitted by support on Tue, 2016-02-23 09:28

Hi Richard,

Ah yes - any fields included in construction of the product HREF will need to be added to the SELECT field list in sitemap.php. In that file, look for the following code at line 55:

$sql = "SELECT normalised_name FROM `".$config_databaseTablePrefix."products` WHERE filename='".database_safe($_GET["filename"])."' LIMIT ".$start.",".$limit;

...and REPLACE with:

$sql = "SELECT id,merchant,normalised_name FROM `".$config_databaseTablePrefix."products` WHERE filename='".database_safe($_GET["filename"])."' LIMIT ".$start.",".$limit;

Cheers,
David.
--
PriceTapestry.com