Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the PATH_INFO mode?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report