You are here:  » Remove .html


Remove .html

Submitted by george-p on Wed, 2013-05-01 19:14 in

if use Rewrite how can remove .html extension from products url ?

thanks

Submitted by support on Wed, 2013-05-01 19:53

Hello George,

Sure - firstly, update your .htaccess and look for the following rule at line 7:

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

...and REPLACE with:

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

Then all you need to do is make the corresponding change in the function that generates product page URLs throughout the script. To do this, edit includes/tapestry.php and look for the following code at line 69 (14/06A) or 66 (15/01A+):

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

...and REPLACE with:

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

Cheers,
David.
--
PriceTapestry.com

Submitted by george-p on Wed, 2013-05-01 20:47

great, thanks

Submitted by ssgupta on Thu, 2013-05-02 06:16

Can we have instructions to implement this in WP/PTO as well. Thanks.

Submitted by support on Thu, 2013-05-02 08:01

Hi ssgupta,

Sure - the rewrite rule (which is not part of .htaccess in WordPress but is built in to the internal rewrite system) is at line 285 in pto.php:

$newrules['('.trim($pto_config_productBaseHREF,'/').')/(.*).html$'] = 'index.php?pagename='.$pto_config_permalink.'&pto_module=product&pto_product=$matches[2]';

...REPLACE with:

$newrules['('.trim($pto_config_productBaseHREF,'/').')/(.*)$'] = 'index.php?pagename='.$pto_config_permalink.'&pto_module=product&pto_product=$matches[2]';

And the corresponding function to generate product links is in pto_common.php, look for the following code at line 48:

return get_bloginfo('url').$pto_config_productBaseHREF.pto_common_hyphenate($product->normalised_name).".html";

...and REPLACE with:

return get_bloginfo('url').$pto_config_productBaseHREF.pto_common_hyphenate($product->normalised_name);

Cheers,
David.
--
PriceTapestry.com

Submitted by TWDesigns on Wed, 2015-09-09 19:32

Is the version above for base script still the correct way to removed .html from the extension with versions 15/01a and 15/09a?

Submitted by support on Thu, 2015-09-10 07:21

Hello Tommy,

Yes all still valid other than the line number of the second modification in the first reply, which is line 66 (15/01A+) - note added above.

Cheers,
David.
--
PriceTapestry.com

Submitted by ajmboy on Tue, 2016-11-29 03:56

Does the sitemap need to be changed and is it pretty much the same to change the other html generated pages?

RewriteRule ^review/(.*).html$ reviews.php?q=$1&rewrite=1&%{QUERY_STRING} [B,L]

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

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

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

Thanks.

Submitted by support on Tue, 2016-11-29 11:40

Hi,

No changes required to sitemap as it generates product page URLs from the tapestry_productHREF() function.

For reviews, modify .htaccess as required e.g.

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

And then make the corresponding changes to the tapestry_reviewHREF() function in includes/tapestry.php - look for the following code at line 82:

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

...and REPLACE with:

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

For merchant / category / brand page 2 / 3 / etc. search results, again modify .htaccess as required e.g.

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

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

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

And then edit html/navigation.php and perform a Search and Replace as follows;

Search:

".html"

Replace:

""

(3 instances)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by TWDesigns on Sat, 2018-03-10 17:50

Does this code still hold true with the newest versions? I tried it but it didn't rewrite my URLS and instead just told me the product no longer existed when loaded.

Submitted by support on Mon, 2018-03-12 11:40

Hi,

The code in the first comment above is current for 16/10A. If the product page is loading but showing product not found, that would indicate a problem with the rewrite - double check the change to the RewriteRule at line 7 which, for .html removed should be:

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

(you can double check the changes to includes/tapestry.php by making sure that the product URL is as you expect it to be after making the changes)

If still no joy, if you could email me the modified .htaccess and includes/tapestry.php I'll check them out further for you...

Cheers,
David.
--
PriceTapestry.com