Determine whether the Rewrite module is supported by PHP $ _ SERVER parameters.

Source: Internet
Author: User

For example.

How can I determine the ISAPI Rewrite environment?

In the ISAPI Rewrite environment, although the above $ _ SERVER ['redirect _ QUERY_STRING '] and $ _ SERVER ['redirect _ url'] parameters are not generated, however, a unique parameter $ _ SERVER ['HTTP _ X_REWRITE_URL '] is generated only in the ISAPI environment, therefore, you can use this parameter to determine the form of the current URL. The method is as follows:

Copy codeThe Code is as follows:
$ IsApi = (isset ($ _ SERVER ['HTTP _ X_REWRITE_URL ']) & strpos ($ _ SERVER ['HTTP _ X_REWRITE_URL'], '? '))? TRUE: FALSE;


By judging the current URL display form, you can know how the program will be executed and whether 301 redirection is required if the current URL is a http://www.jb51.net /? = P1141, use 301 to redirect to http://www.jb51.net/p1141.html, as shown below:

Copy codeThe Code is as follows:
Header ("HTTP/1.1 301 Moved Permanently ");
Header ("Location: http://www.jb51.net/p1141.html ");


Then, the process of the program after redirection ensures page unification, and also solves the issue of ISAPI and Apache Rewrite loop redirection.

Determine whether ISAPI and Apache are redirected:

ISAPI usage:

Copy codeThe Code is as follows:
$ _ SERVER ['HTTP _ X_REWRITE_URL ']


Apache usage:

Copy codeThe Code is as follows:
$ _ SERVER ['redirect _ QUERY_STRING '] or $ _ SERVER ['redirect _ url']


As long as you know how to use the parameters of $ _ SERVER, you can easily solve the issue of ISAPI and Apache Rewrite loop redirection.

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.