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.