Apache Acceptpathinfo instruction using the introduction _php tutorial

Source: Internet
Author: User
when learning Zfdemo, mention setting acceptpathinfo instructions.

Sometimes when we do virtual static or make the path look beautiful, you may see HTTP://WWW.EXAMPLE.COM/INDEX.PHP/HTML1 such URL address, and in the actual access is the root directory of the index.php file, and put/ HTML1 is passed to the script as a PATH_INFO environment variable. For Apache, the above address can be run correctly depending on the configuration of the Acceptpathinfo directive

acceptpathinfo Directive

Indicates whether to accept requests with redundant path name information
Grammar Acceptpathinfo on| Off| Default
Defaults acceptpathinfo Default
Scope Server config, virtual host, directory,. htaccess
Overwrite Item FileInfo
State Core (C)
Module Core
Compatibility is only available in Apache 2.0.30 and later versions

This directive determines whether to accept requests that follow redundant pathname information after the actual file name (or a nonexistent file in the actual directory). This redundant pathname information can be passed to the script as a PATH_INFO environment variable.

For example, assuming that the directory that/test/points to contains only one file: here.html, then the/test/here.html/more and/test/nothere.html/more requests will set the PATH_INFO environment variable to "/ More ".

range of values for Acceptpathinfo directives:

Off
It is accepted only if a request is mapped to a path that is actually present. Thus, a request that follows a pathname after a real file name, such as the above/test/here.html/more, will return a "404 Not FOUND" error.
On
The request can be accepted as long as the leading path can be mapped to a file that is actually present. Thus, if the above/test/here.html can be mapped to a valid file, then the request to/test/here.html/more will be received.
Default
The request to receive additional pathname information is determined by its corresponding processor. The core processor corresponding to normal text rejects Path_info by default. The processors used for servo scripts, such as Cgi-script and Isapi-isa, accept path_info by default.
The primary purpose of the ACCEPTPATHINFO directive is to allow you to override the processor's default settings for whether or not to accept path_info. This kind of coverage is necessary. For example, when you use a filter like includes to produce content based on Path_info. The core processor usually rejects such a request, and you can make such a script possible with the following configuration:

Options +includes
Setoutputfilter includes
Acceptpathinfo on

Apache 2.0 above the default is no Acceptpathinfo

Remove the acceptpathinfo from the server above the APACH2.0.30, and add Acceptpathinfo on to the http.conf if needed. That is the original

Options FollowSymLinks includes
AllowOverride None
Change into
Options FollowSymLinks includes
AllowOverride None
Acceptpathinfo on

This directive determines whether to accept additional path information that is contained in a certain file (or a nonexistent file of an existing directory). This path information will appear in the script as a PATH_INFO environment variable.
For example, suppose/test/is pointing to a directory that contains only one file: here.html. Then the request for/test/here.html/more and/test/nothere.html/more will be/more such a path_info variable.
The three parameters of the Acceptpathinfo directive are:
Off
It is accepted only if a request is mapped to a path that is actually present. Thus, a request that follows a pathname after a real file name, such as the above/test/here.html/more, will return a 404 Not Found error.
On
If the previous path is mapped to a real-world file, this request will be accepted. If/test/here.html maps a valid file, in the example above/test/here.html/more the request is accepted.
Default
The processing of requests for additional path names is determined by their corresponding processors. The core processor corresponding to normal text rejects Path_info by default. The processors used for servo scripts, such as Cgi-script and Isapi-isa, accept path_info by default.

The global variable $_server[' path_info ' in PHP is a useful parameter, and 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 use URLs like Http://www.test.com/index.php?c=search&m=main, which not only look very strange, And it's also very unfriendly to search engines. Many search engines ingest, will ignore the content after query string, although Google will not ignore query string, but for other pages without query string, will give a higher PR value.

here is a very simple code for parsing path_info:

Copy CodeThe 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";
?>


PHP file name after the slash "/" not normal access, reported not found error
After the system is bad, after reloading the system, configure the PHP environment. The software used is the same as the previous version.

After the environment is configured, because the work items are single entry files, the index.php file is preceded by a slash to enter. can be accessed before changing the system, can be excluded from the software version issue.

Just want to enter the work project, reported not found do not know why. After testing, the PHP file name after the slash "/" does not access the normal

Ask a lot of people, not the results. Google degree Niang not fruit

Find a senior PHP engineer in the company
Says Apache has such an instruction: Acceptpathinfo

In the Apache configuration file, add: Acceptpathinfo on is OK.

http://www.bkjia.com/PHPjc/326345.html www.bkjia.com true http://www.bkjia.com/PHPjc/326345.html techarticle when learning Zfdemo, mention setting the Acceptpathinfo directive. Sometimes when we do virtual static or make the path look beautiful, we may see HTTP://WWW.EXAMPLE.COM/INDEX.P ...

  • 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.