21

I need to pass / as a variable as part of a URL.

My structure looks like this: www.domain.com/listings/page-1/city-Burnaby+South/type-Townhome/bedroom-2/bathroom-2

In this case, it ultimately boils down to listings.php and everything else beyond it becomes parameters taht my PHP script parses through using the $_SERVER['REQUEST_URI'] var.

However when one of hte variables becomes "Apartment/Condo" and the / becomes %2F via urlencode() in PHP when the URL is generated, the whole thing chokes and I get a "Not Found" error.

How do I pass the / without breaking the URL? What am I missing? I thought the whole point of these urlencode() characters (%2F, %20 etc.) were there to escape these issues.

jeffkee
  • 5,106
  • 12
  • 44
  • 76

2 Answers2

44

Urls with %2f / or %5c \ return a 404 from Apache for security purposes.

You may modify Apache config to enable AllowEncodedSlashes On or NoDecode. Keep in mind that this may introduce unintended security issues, which this "feature" is designed to mitigate.

Apache docs: http://httpd.apache.org/docs/current/mod/core.html#allowencodedslashes

Solved:

This one got me too -- thanks for the question

Community
  • 1
  • 1
here
  • 2,790
  • 25
  • 30
-4

You can equally just do urldecode();

Mob
  • 10,958
  • 6
  • 41
  • 58
  • The URL is passed and decoded using urldecode(). My issue is that it doesn't even render to the PHP page - it returns a 404 as soon as there is a %2F included in the request somewhere. – jeffkee Feb 14 '12 at 04:59
  • The request fails to get to invoking PHP, so no this is not a solution – Tobias Hagenbeek Dec 20 '20 at 17:43