Determine whether the Rewrite module is supported from PHP $_SERVER related parameters_PHP tutorial

WBOY
Release: 2016-07-21 16:12:55
Original
1151 people have browsed it

If it is a URL in the form of http://www.jb51.net/p1141.html, it can be analyzed through the difference between the values ​​​​of $_SERVER['REQUEST_URI'] and $_SERVER['QUERY_STRING']. The most important thing is if the page is passed through a duplicate Orientation will generate two parameters, $_SERVER['REDIRECT_QUERY_STRING'] and $_SERVER['REDIRECT_URL'], so it is very simple to judge whether the page is redirected. You only need to judge the existence of these two values, but this is only in Valid only in Apache environment.

How to judge if it is an ISAPI Rewrite environment?

If it is an ISAPI Rewrite environment, although the above two parameters $_SERVER['REDIRECT_QUERY_STRING'] and $_SERVER['REDIRECT_URL'] will not be generated, it will also generate its own unique parameter $_SERVER[ 'HTTP_X_REWRITE_URL'], this parameter is only generated in the ISAPI environment, so you can use this parameter to determine what form the current URL is. The method is as follows:

Copy Code The code is as follows:

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


By judging the display form of the current URL, you can know how the program will execute and whether a 301 redirect is needed. If the current URL is http://www.jb51 .net/?=p1141, you need to use 301 redirection to http://www.jb51.net/p1141.html, as follows:

Copy code The code is as follows:

header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.jb51.net/p1141.html") ;


Then go through the post-redirect program process. This ensures the unity of the page and also solves the Rewrite loop redirection problem of ISAPI and Apache.

Judge whether ISAPI and Apache are redirected:

ISAPI usage:

Copy code The code is as follows:

$_SERVER['HTTP_X_REWRITE_URL']


Apache uses:

Copy code The code is as follows:

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


As long as you master the usage of each parameter of $_SERVER , you can easily solve the Rewrite loop redirection problem of ISAPI and Apache.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313568.htmlTechArticleIf it is a URL in the form of http://www.jb51.net/p1141.html, it can be passed $_SERVER[ 'REQUEST_URI'] and $_SERVER['QUERY_STRING'] values ​​are analyzed. The most important thing is that if the page is redirected...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!