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

How to support Pathinfo and URl Rewrite modes of ThinkPHP under Nginx

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, I will talk to you about how to support ThinkPHP's Pathinfo and URl Rewrite mode under Nginx. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

1. ThinkPHP provides the official solution for ThinkPHP, as follows:

Location ~ .php {# original code # defines the variable $path_info to store pathinfo information set $path_info "; # defines the variable $real_script_name to store the real address set $real_script_name $fastcgi_script_name # if the address matches the regular expression in quotation marks if ($fastcgi_script_name ~ "^ (. +?\ .php) (/. +) $") {# assign the file address to the variable $real_script_name set $real_script_name $1 # assign the parameter 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;}

In this way, the nginx server can support pathinfo. However, if you want to support the mode with URL_MODE set to 2 for ThinkPHP, you also need to configure rewrite rules. Locate the access_log statement and add the following statement above it:

# if the request is neither a file nor a directory, execute the rewriting rule if (!-e $request_filename) {# address as the parameter rewrite to the index.php. Rewrite ^ (. *) $/ index.php?s=$1 last; # if it is a subdirectory, use the following sentence to change subdir to the directory name. # rewrite ^ / subdir/ (. *) $/ subdir/index.php/$1;}

2016.09

After reading the above, do you have any further understanding of how ThinkPHP's Pathinfo and URl Rewrite modes are supported under Nginx? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Servers

Wechat

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

12
Report