A solution to the problem of nginx anti-slash automatic decoding _nginx

Source: Internet
Author: User

Nginx will decode the characters in the URI and pass it to fastcgi, which is usually OK, but my search term contains a backslash and an encoded address.

Copy Code code as follows:

/search/madmanfoo%2flovesong/

Nginx Pass to PHP address becomes, I use pathinfo so can't get the correct result
Copy Code code as follows:

/search/madmanfoo/lovesong/

The Nginx official website to find all over and did not find to prevent the automatic decoding configuration, really do not want to two times code, from http://stackoverflow.com/questions/8264239/ Nginx-unescapes-2f-to-a-forward-slash-how-can-i-stop-it found a similar post, look at the sample can only two times encoded, it is said that the official advice. In order to preserve the beauty of the address, only two encodings of the backslash that affect pathinfo are made.
Copy Code code as follows:

$keyword =urlencode ($keyword);
$keyword =str_replace (Array ('%2f ', '%2f '), '%252f ', $keyword);

If there is a better solution, please correct me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.