Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the PATH_INFO mode?

Shulou Source: shulou.com Published: 2022-06-03 06:41:52 09月10日 Update

This article introduces the relevant knowledge of "what is the PATH_INFO mode". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

One: what is the PATH_INFO mode?

PATH_INFO mode is a kind of pseudo-static.

We can use PATH_INFO instead of Rewrite to implement pseudo-static pages, and many PHP frameworks also use PATH_INFO as a routing carrier

Pseudo-static page is a bridge between static URL and dynamic URL. It means that dynamic URL removes its dynamic parameters by means of URL rewriting to make URL static, but it does not rewrite URL in the actual web page directory.

To put it simply, pseudo-static URL is to convert a disguised file name or address through the server to make the page similar to a static page, but there is no independent file on the server, and its essence is a dynamic page.

PATH_INFO is a parameter in the server status, and PHP can view the content through $_ SERVER ['PATH_INFO']

Second: how to analyze

Apache

In Apache, Accept pathinfo is accepted by default for PHP scripts when not configured

The configuration under apache is as follows

RewriteEngine on RewriteCond% {REQUEST_FILENAME}!-d RewriteCond% {REQUEST_FILENAME}!-f RewriteRule ^ (. *) .html$ index.php/$1 [QSA,PT,L]

Nginx

Support for pathinfo mode through fastcgi_split_path_info instructions

The simple configuration is as follows:

Server {listen 80; server_name chris.demo.com; root/ home/wwwroot/chris/; location / {if (!-e $request_filename) {rewrite ^ (. *) $/ index.php?s=/$1 last; break;}} location ~\ .php (. *) ${fastcgi_index index.php # # unix socket communication is used by default, and then the configuration of php-fpm is modified to tcp communication # # fastcgi_pass unix:/run/php/php7.3-fpm.sock; # # unix socket fastcgi_pass 127.0.0.1 fastcgi_pass unix:/run/php/php7.3-fpm.sock; 9000 # # TCP # # add the fastcgi_split_path_info instruction to match URI to the URI and pathinfo variables of the PHP script # # that is, $fastcgi_script_name and $fastcgi_path_info fastcgi_split_path_info ^ (. +\ .php) (. *) $ # # to be able to read the variable pathinfo in PHP # # assign the pathinfo part matched to the fastcgi_split_path_info instruction to PATH_INFO # # so that the value fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info exists in $_ SERVER ['PATH_INFO'] in PHP. Include fastcgi_params;}}

Restart the nginx and php-fpm service after the configuration is completed, and you can successfully request

Create the entry file index.php, and get the information through $_ SERVER ['PATH_INFO']

Http://chris.demo.com/index.php/Home/index/chris

Tags: Static mode page configuration dynamic instruction file service content server information entry parameter variable actual more knowledge script communication utility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology OPPO Reno Shulou Tech Info Linux