-1

I have a few links that look like this:

https://www.example.com/find?category=food%20%26%20drink

Clicking on the link should take me to a page where I can GET the variable, and it SHOULD read "food & drink".

However, when I click the link, it takes me to this url instead:

https://www.example.com/find?category=food%2520%2526%2520drink

the variable reads: food%20%26%20drink.

If I paste the first url into the search-bar directly, it works fine. But if I click on it as a link, then it gets re-encoded somehow.

Any idea how to get it to read "food & drink" even though it comes from a different page?

many thanks in advance!

user3817799
  • 147
  • 1
  • 7
  • 2
    Works fine, issue not reproducible. You need to show your code. See [ask] and [mcve] – Pinke Helga Jan 31 '19 at 00:09
  • `urldecode` function in php should decode url params – Anand G Jan 31 '19 at 00:11
  • 2
    How are you creating the link? Looks like you're double-encoding it. Seems to be working just fine here ~ [JSFiddle](https://jsfiddle.net/philbrown/er9yo140/) – Phil Jan 31 '19 at 00:13

2 Answers2

0

Realized the links were written as http instead of https. Consequently, they were being re-written by the htaccess file to https when clicked, and also being re-encoded at the same time.

Ahtisham
  • 9,170
  • 4
  • 43
  • 57
user3817799
  • 147
  • 1
  • 7
-1

The link you have is double encoded. The possible solution to this would be

  1. Find line of code where the link getting encoded again and make suer not encode if encoded already. Couple of examples are given here Click Here
  2. If there is no way you can change the code form where the URL is getting generated, then you have to use urldecode twice to parse the url params
<?php
$query = "https://www.example.com/find?category=food%2520%2526%2520drink";

    $param = explode("=", $query);

    print_r(urldecode(urldecode($param[1])));
?>

Hope this helps!

Anand G
  • 3,130
  • 1
  • 22
  • 28
  • 1. This will break if there is more than one URL parameter. 2. [`parse_url()`](https://secure.php.net/manual/en/function.parse-url.php) and [`parse_str()`](https://secure.php.net/manual/en/function.parse-str.php) would comprise a proper solution. 3. OP has asked how to stop this from happening, not how to reverse it. – Sammitch Jan 31 '19 at 01:00
  • Thats what I mention, if he is sure this is the exact format OP is looking then it is fine, else it has to be fixed from root – Anand G Jan 31 '19 at 01:15