Forum Moderators: phranque

Message Too Old, No Replies

Remove slash from a query string

         

lokeshshettyk

6:51 am on May 14, 2009 (gmt 0)

10+ Year Member



Hi,
This may be a stupid question. I don't even know if this is possible. I want to remove the back slash before the apostrophe in a query string. e.g. http://www.example.com/search/?q=ben+and+berry\'s. when i initially type in the search keyword it comes fine like ...?q=ben+and+berry's but when paginate it adds up a slash like http://www.example.com/search/page/2/?q=ben+and+berry\'s, http://www.example.com/search/page/3/?q=ben+and+berry\\'s and so on.

Here is the code I have been using;

# Search
RewriteCond %{QUERY_STRING} ^q=$
RewriteRule . [%{HTTP_HOST}...] [L,R]
RewriteRule ^search/$ /index.php?&a=search [QSA,L]
RewriteRule ^search/([0-99]+)/?$ /index.php?&a=search&postpage=$1 [QSA,L]

I appreciate all your help/suggestions on this.

Many thanks,
~ KLS ~

jdMorgan

2:17 pm on May 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your best bet would be to find the problem (which is in your script's 'paginating' function), rather than trying to use code to correct the problem after the bad URL has already been 'published' on the Web.

You can use a rewriterule to clean up search engine results and prevent errors from links and bookmarks that have been created using the incorrect URLs, but you need to fix the problem at its source. For some reason, the PHP code is double-escaping the single quote when the previously-escaped query is used to 'build' the query for the next page. It's a rather obvious bug, and should be easy for you or the developer to to fix: If the pagination function is called for the first time, then escape all characters, but if it is being called for a second or subsequent page, or by a "next" or "previous" function, then only escape slashes if they don't precede a character that needs to be escaped.

If you can't get this fixed in the source code, please post again. I've got some code lying around to extract pieces of the query string, but it is complex and nasty to decipher.

Jim

lokeshshettyk

3:08 pm on May 14, 2009 (gmt 0)

10+ Year Member



Thanks Jim, I would ask my dev to look at it. appreciate your help

~ KLS ~