Two ways for nginx to open pathinfo mode

Hits: 0

*Someone may ask why apache doesn’t have this problem?

Apache generally runs php as a module, and apache can set the value of $_SERVER[‘PATH_INFO’] without additional configuration.

  1. The new version of nginx can also use the fastcgi_split_path_info command to set PATH_INFO. The old method is no longer recommended. Add the following configuration in the location section.

fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;  
fastcgi_param PATH_INFO $fastcgi_path_info;  
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

Just restart nginx

  1. Open the nginx.conf configuration file and find a place similar to the following code (different versions of nginx may be slightly different , but generally the same)

location ~ \.php$  
{  
                #original code   
}

Change it to:

#Remove $ is to not match the end of the line, that is, you can match .php/ to achieve pathinfo   
location  ~ \.php  
        {  
                #Original code  

                #Define variable $path_info   
                set  $path_info  "" ;  
                 #Define variable $real_script_name to store the real address   
                set  $real_script_name  $fastcgi_script_name ;  
                 #If the address matches the regular expression in quotes   
                if ( $fastcgi_script_name  ~ "^(.+? \.php)(/.+)$") {  
                         #Assign the file address to the variable $real_script_name   
                        set  $real_script_name  $1 ;  
                         #Assign the parameters after the file address to the variable $path_info   
                        set  $path_info  $2 ;  
                }  
                #Configure some parameters of fastcgi   
                fastcgi_param SCRIPT_FILENAME $document_root $real_script_name ;  
                 fastcgi_param SCRIPT_NAME $real_script_name ;  
                 fastcgi_param PATH_INFO $path_info ;  
        }

You may also like...

Leave a Reply

Your email address will not be published.