/ in URL breaks and does not reference to the .php

2019-01-09 06:02发布

问题:

This question already has an answer here:

  • urlencoded Forward slash is breaking URL 12 answers

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.

回答1:

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:

  • Receive an HTTP 400 error if %2F is part of the GET URL in JBOSS

This one got me too -- thanks for the question



回答2:

You can equally just do urldecode();



标签: php apache url