PHP recognizes url rewriting requests

Source: Internet
Author: User
Currently, many PHP programs use url rewriting technology to optimize URLs. But sometimes we need to distinguish the default url request from the url rewrite request in PHP. How can this problem be solved? My solution is to find the answer in the constant $ _ SERVER. In different servers, $ _ SERVER will have an index to record the path before rewriting the request access rewrite,

Currently, many PHP programs use url rewriting technology to optimize URLs. But sometimes we need to distinguish the default url request from the url rewrite request in PHP. How can this problem be solved? My solution is to find the answer in the constant $ _ SERVER. In different servers, $ _ SERVER will have an index to record the path before rewriting the request access rewrite,

Currently, many PHP programs use url rewriting technology to optimize URLs. But sometimes we need to distinguish the default url request from the url rewrite request in PHP. How can this problem be solved?

My solution is to find the answer in the constant $ _ SERVER. In different servers, $ _ SERVER will have an index to record the path before rewriting the request access rewrite, indexes of some mainstream servers are as follows:

IIS7 + Rewrite Module-> $ _ SERVER ['HTTP _ X_ORIGINAL_URL ']

IIS6 + ISAPI Rewite-> $ _ SERVER ['HTTP _ X_REWRITE_URL ']

Apache2-> $ _ SERVER ['request _ url'] or $ _ SERVER ['redirect _ url']

Nginx-> $ _ SERVER ['request _ URI ']

The result is that you only need to determine the parameters HTTP_X_ORIGINAL_URL, HTTP_X_REWRITE_URL, REQUEST_URI, and REDIRECT_URL. Then, you can determine in PHP that the request url is from the address that is rewritten or in the default format.

Note: url rewriting

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.