Home > Backend Development > PHP Tutorial > Introduction to the use of APACHE's AcceptPathInfo directive_PHP tutorial

Introduction to the use of APACHE's AcceptPathInfo directive_PHP tutorial

WBOY
Release: 2016-07-21 15:14:06
Original
1002 people have browsed it

When learning zfdemo, I mentioned setting the AcceptPathInfo command.

Sometimes when we are doing virtual staticization or making the path look beautiful, we may see http://www.example A URL address like .com/index.php/html1 is actually accessed from the index.php file in the root directory, and /html1 is passed to the script as the PATH_INFO environment variable. For apache, whether the above address can run correctly depends on the configuration of the AcceptPathInfo directive

AcceptPathInfo directive

indicates whether to accept requests with redundant path name information
Syntax AcceptPathInfo On|Off|Default
Default value AcceptPathInfo Default
Scope server config, virtual host, directory, .htaccess
Override item FileInfo
State core (C)
Module core
Compatibility is only available in Apache 2.0.30 and later

This directive determines whether to accept requests that follow the actual file name (or a non-existent file in the actual directory) followed by redundant pathname information . This extra pathname information can be passed to the script as the PATH_INFO environment variable.

For example, assuming that the directory pointed to by /test/ contains only one file: here.html, then requests for /test/here.html/more and /test/nothere.html/more will be The PATH_INFO environment variable is set to "/more".

The value range of the AcceptPathInfo directive:

Off
A request will only be accepted if it is mapped to a real path. Thus, a request that follows the real filename followed by a pathname like /test/here.html/more above will return a "404 NOT FOUND" error.
On
As long as the leading path can be mapped to a real existing file, the request can be accepted. In this way, as long as the above /test/here.html can be mapped to a valid file, the request for /test/here.html/more will be received.
Default
Whether a request with redundant pathname information is accepted is determined by its corresponding processor. Core processors that handle normal text reject PATH_INFO by default. Processors used for server scripts, such as cgi-script and isapi-isa, will accept PATH_INFO by default.
The primary purpose of the AcceptPathInfo directive is to allow you to override the processor's default setting of whether to accept PATH_INFO. This coverage is necessary. For example, when you use a filter like INCLUDES to generate content based on PATH_INFO. The core processor usually rejects such requests, and you can enable such scripts with the following configuration:

Options +Includes
SetOutputFilter INCLUDES
AcceptPathInfo On

The default in apache 2.0 and above is that there is no acceptpathinfo

Acceptpathinfo has been removed from APACH2.0.30 and above servers; if necessary, you need to add the AcceptPathInfo On entry in http.conf. That is, the original

Options FollowSymLinks includes
AllowOverride None
is changed to
Options FollowSymLinks includes
AllowOverride None
 AcceptPathInfo On

This command determines whether to accept Contains path information appended to a certain file (or a non-existent file in an existing directory). This path information will appear in the script as the PATH_INFO environment variable.
For example, assume that the directory pointed to by /test/ contains only one file: here.html. Then requests for /test/here.html/more and /test/nothere.html/more will get PATH_INFO variables like /more. The three parameters of the
AcceptPathInfo directive are:
off
A request will only be accepted if it is mapped to a real path. Thus, a request such as /test/here.html/more above with a pathname following the real filename will return a 404 NOT FOUND error.
on
If the preceding path maps to a real file, the request will be accepted. If /test/here.html maps to a valid file, the request for /test/here.html/more in the above example will be accepted.
default
The processing method of requests with additional path names is determined by its corresponding processor. Core processors that handle normal text reject PATH_INFO by default. Processors used for server scripts, such as cgi-script and isapi-isa, will accept PATH_INFO by default.

The global variable $_SERVER['PATH_INFO'] in PHP is a very useful parameter. Many CMS systems use this parameter when beautifying their URLs.

For the following URL:
http://www.test.com/index.php/foo/bar.html?c=index&m=search
We can get $_SERVER['PATH_INFO '] = '/foo/bar.html', and at this time $_SERVER['QUERY_STRING'] = 'c=index&m=search';
Usually, when we first start writing PHP programs, we will use things like: http A URL like ://www.test.com/index.php?c=search&m=main not only looks very strange, but is also very unfriendly to search engines. Many search engines will ignore the content after the Query String when indexing. Although Google will not ignore the Query String, it will give a relatively high PR value to other pages that do not contain the Query String.

The following is a very simple code to parse PATH_INFO:

Copy the code The code is as follows:

if( !isset( $_SERVER['PATH_INFO'] ) ){
$pathinfo = 'default';
}else{
$ pathinfo = explode('/', $_SERVER['PATH_INFO']);
}
if( is_array($pathinfo) AND !empty($pathinfo) ){
$page = $pathinfo[1 ];
}else{
$page = 'a.php';
}
require "$page.php";
?>


The php file name with a slash "/" cannot be accessed normally, and a not found error is reported
After the system is broken, reinstall the system and configure the php environment. The software used is the same as in previous versions.

After the environment is configured, since the work projects are all single-entry files, a slash is added after the index.php file to enter. It can be accessed before changing the system, which can eliminate software version problems.

Just when I want to enter the work project, it reports not found. I don’t know why. After testing, I learned that the php file name with a slash "/" cannot be accessed normally

I asked many people, but to no avail. Google Du Niang failed

Find a senior PHP engineer in the company
It is said that apache has such a command: AcceptPathInfo

Add: AcceptPathInfo on in the apache configuration file and it will be ok.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326345.htmlTechArticleWhen learning zfdemo, I mentioned setting the AcceptPathInfo directive. Sometimes we are doing virtual staticization or making the path look beautiful , you may see http://www.example.com/index.p...
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