You are here:  » Replace character in .htaccess

Support Forum



Replace character in .htaccess

Submitted by philh on Sat, 2008-03-29 22:22 in

Hi Dave,

I have a special character in the product name (%) and I want it to stay there - but the URL obviously won't work with the % sign in it. Is there a way of keeping the product name but changing the URL so it doesn't include the % sign by using .htaccess or something?

Regards
Phil

Submitted by support on Sun, 2008-03-30 08:58

Hi Phil,

The % character should be urlencoded() wherever it is written into the URL; so if you have permitted this character in all the places that it would need to be changed then is should work - but i'm afraid nothing is guaranteed with special characters in the URL when it comes to re-writing etc!

To allow the character in, the change is just to the following code in includes/admin.php from:

    /* apply standard filters */
    $record[$admin_importFeed["field_name"]] = tapestry_normalise($record[$admin_importFeed["field_name"]]);

to:

    /* apply standard filters */
    $record[$admin_importFeed["field_name"]] = tapestry_normalise($record[$admin_importFeed["field_name"]],"%");

Having done that, the % will be imported and should be displayed correctly wherever you see the product name in search results (as long as you search for it without the %); but then the same character is also stripped when the query is normalised. At the top of the following files:

search.php
products.php
reviewss.php

...you will see the following code (line 4):

$q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\."):"");

This also needs to be changed to allow any new characters in; as follows:

$q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],"%:\."):"");

If it's still not working after checking the above changes, if you could email me a link to the search results showing a product with % in the name and i'll check it out for you...

Cheers,
David.

Submitted by philh on Sun, 2008-03-30 12:49

I know it's not conventional but I don't know about databases etc and with the knowledge I've picked up about PT, I thought I could upload a spreadsheet of discount codes and use PT to display them in the discounts section of the site and it works quite nicely. That's OK, right?
An example is here: http://www.hanlor.co.uk/discount-codes/vouchers/Eshopmegastore/
Each 'product' is an offer so obviously you can go into the offer but if the title is '5% off everything', the URL has a % in it and sends a 'Bad Request'.
Those allowed me to import the % safely (previously I used a search and replace filter to create the %) but the URL still won't work.

Cheers
Phil

Submitted by support on Sun, 2008-03-30 13:01

Hi Phil,

I think I can see what's going on here - obviously it's quite heavily modified PT; but I'm assuming that the page you linked to is displayed by html/searchresults.php, using links built up in search.php.

What's happening is that because non-URL-safe characters are not normally permitted the product name is not urlencoded() when the link is created (when in rewrite mode, which you are using). To fix this, in search.php, search for the following line:

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

...and replace this with:

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

That should at least prevent the "Bad Request"...

Cheers,
David.

Submitted by philh on Sun, 2008-03-30 13:17

That's done the trick, cheers Dave :)