Introduction to APACHE's AcceptPathInfo directive

  • 2020-05-27 04:39:02
  • OfStack

Setting the AcceptPathInfo directive was mentioned when learning zfdemo.

Sometimes we are doing a virtual static or let path looks very beautiful, may see http: / / www example. com/index php/html1 URL address, and is on a visit to the actual root directory index. php files, and convey/html1 as PATH_INFO environment variables to the script. For apache, the correct operation of the above address depends on the configuration of the AcceptPathInfo directive

AcceptPathInfo instruction

Specifies whether to accept requests with redundant pathname information
Grammar AcceptPathInfo On | Off | Default
The default value is AcceptPathInfo Default
Scope server config, virtual host, directory,.htaccess
Covered item FileInfo
State core (C)
Module core
Compatibility is only available in Apache 2.0.30 and later

This directive determines whether to accept a request for redundant pathname information following the actual file name (or one file that does not exist in the actual directory). This extra pathname information can be passed to the script as the PATH_INFO environment variable.

, for example, assume that directory/test/points to include only 1 file: here. html, so to/test/here html/more and/test nothere html/more request PATH_INFO environment variable will be set to "/ more".

Value range of AcceptPathInfo instruction:

Off
Only when a request is mapped to a real path will it be accepted. . So, if above/test here html/more after the real name of the file to follow a path name request would return a "404 NOT FOUND" error.
On
The request can be accepted as long as the leading path can be mapped to a real file. . In this way, as long as the above/test/here html can be mapped to a valid file, so to/test/here html/more request will be received.
Default
Whether or not to receive a request with redundant pathname information is determined by its corresponding processor. Core processors that correspond to plain text reject PATH_INFO by default. 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 regarding whether or not 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 will typically reject such a request, and you can make such a script possible with the following configuration:

Options +Includes
SetOutputFilter INCLUDES
AcceptPathInfo On

The default above apache 2.0 is that there is no acceptpathinfo

acceptpathinfo is removed from servers above APACH2.0.30; If necessary, add AcceptPathInfo On to http.conf. That is the original

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

This directive determines whether or not to accept path information that is appended to a certain file (or a nonexistent file in an existing directory). This path information will appear in the script as the PATH_INFO environment variable.
For example, suppose /test/ points to a directory containing only one file: here.html. As to/test/here html/more and/test nothere html/more requests will get/more PATH_INFO variables.
The three parameters of the AcceptPathInfo instruction are:
off
It is only accepted if a request is mapped to a real path. . So, if above/test here html/more such after the real name of the file to follow a path name request will return a 404 NOT FOUND errors.
on
If the previous path is mapped to a real file, the request will be accepted. If/test here html mapping with a valid file, in case/test/here html/more this request will be accepted.
default
How requests for additional pathnames are handled is determined by the corresponding processor. Core processors that correspond to plain text reject PATH_INFO by default. 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 that many CMS systems use to beautify their URL.

For the following url:
http://www.test.com/index.php/foo/bar.html?c=index & m=search
We get $_SERVER['PATH_INFO'] = '/foo/ bar.html ', while $_SERVER['QUERY_STRING'] = 'c=index & m=search';
Usually, we first started PHP programming, will use such as: http: / / www test. com/index php? c = search & m=main such URL, this URL not only looks very strange, but is also very unfriendly to search engines. Many search engines will ignore the content after Query String, while google will not ignore Query String, but for other pages that do not contain Query String, it will give a higher PR value.

Here is a very simple code to parse PATH_INFO:

 
<?php 
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 with slash "/" cannot be accessed normally, not found error is reported
After system failure, configure php environment after system reinstallation. The software is the same as the previous version.

After the environment is configured, the work items are all single entry files, so the index.php files can only be entered with a slash at the back. Before changing the system can be accessed, you can eliminate the software version problem.

As soon as I wanted to enter the work project, I reported not found for some unknown reason. After testing, we learned that the file name of php with the slash "/" cannot be accessed normally

Asked many people, but failed. google baidu failed

Find 1 senior php engineer of the company
It says apache has this command: AcceptPathInfo

Add: AcceptPathInfo on to ok configuration file.

Related articles: