The PHP $_SERVER parameter determines whether the Rewrite module is supported or not

  • 2020-09-16 07:25:05
  • OfStack

If it is / / www. ofstack. com/p1141 html form URL, through $_SERVER [' REQUEST_URI] and $_SERVER [' QUERY_STRING] value to analyze the difference between, is the most important is if the page through the redirect will generate $_SERVER [' REDIRECT_QUERY_STRING] and $_SERVER [' REDIRECT_URL] on two parameters, So it's very easy to determine whether a page is redirected or not, just if these two values exist, but that's only true in the Apache environment.

What if it's an ISAPI Rewrite environment?

If it is an ISAPI Rewrite environment, it will not produce the above parameters $_SERVER['REDIRECT_QUERY_STRING'] and $_SERVER['REDIRECT_URL'], but it will also produce its own unique parameter $_SERVER[' REDIRECT_ES39en_ES40en ']. This parameter will only be generated in the ISAPI environment, so it can be used to determine the current URL form, as follows:

 
$isApi = (isset($_SERVER['HTTP_X_REWRITE_URL']) && strpos($_SERVER['HTTP_X_REWRITE_URL'],'?')) ? TRUE : FALSE;

By judging the current URL display, you will know how the program will execute and whether a 301 redirect is needed. If the current URL is // www.ofstack.com /? = p1141, you may need to use a 301 redirect to / / www ofstack. com/p1141 html, as follows:

 
header("HTTP/1.1 301 Moved Permanently");
header("Location://www.ofstack.com/p1141.html");

Then go to the process after the redirection, which ensures the unification of the page 1, and also solves the Rewrite loop redirection problem of ISAPI and Apache.

Whether ISAPI and Apache are redirected or not:

ISAPI use:

 
$_SERVER['HTTP_X_REWRITE_URL']

Apache use:

 
$_SERVER['REDIRECT_QUERY_STRING'] or $_SERVER['REDIRECT_URL']

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

The following is the supplement of other netizens can refer to 1

WordPress USES 301 redirects to make non-primary domain (non-ES94en) hops a simple thing, but the loop redirection problem is caused by not figuring out the difference between $_SERVER[' HTTP_X_REWRITE_URL'] and $_SERVER[' REQUEST_URI'].
Now consider the difference between $_SERVER[' HTTP_X_REWRITE_URL'] and $_SERVER[' REQUEST_URI']
The first thing to correct for part 1 is that IIS+PHP does not support $_SERVER[' REQUEST_URI']
No, it is not supported by PHP Version version, php4.4.0 does not support $_SERVER[' REQUEST_URI'], php5.2.5 has added support;

$_SERVER[' REQUEST_URI'] is used to get the current URL
For example: / / www. ofstack. com/index php & # 63; p=3
$_SERVER[' REQUEST_URI'] gets/index.php ? p=3.
$_SERVER[" HTTP_X_REWRITE_URL "] gets the current URL under IIS and the value under apache is empty

Such as:
Current URL: / / www. ofstack. com /

Under IIS environment:
$_SERVER [' REQUEST_URI '] = / index php
"HTTP_X_REWRITE_URL" $_SERVER [] = /
Under apache environment:
$_SERVER [' REQUEST_URI '] = /
$_SERVER [] "HTTP_X_REWRITE_URL" ="

Current URL: / / www. ofstack. com/index php
Under IIS environment:
$_SERVER [' REQUEST_URI '] = / index php
$_SERVER [" HTTP_X_REWRITE_URL "] = / index php

apache:
$_SERVER [' REQUEST_URI '] = / index php
$_SERVER [] "HTTP_X_REWRITE_URL" ="

All I need is to determine if the current URL contains/index.php

It can be seen that the domain name redirect in IIS first replaces $_SERVER[' REQUEST_X_ES239en_ES240en '] with $_SERVER[' HTTP_X_REWRITE_URL '], and the reverse is true for apache.


Related articles: