# Recommended: "Method to hide ".php" in URL: First find and open the "nginx.conf" configuration file; then add the content "location / {ttry_files $uri $uri/ $uri.php$is_args$args; }"; Finally save the changes.
PHP Video Tutorial》
Nowadays, many people like to use nginx as a web server to deploy websites. nginx is also very convenient to configure. If your website is developed in PHP language, let’s teach you a simple trick below. Quickly hide the php suffix of the web page and implement a Pretty URL.
Easy to use nginx’s try_files directive.
location / {ttry_files $uri $uri/ $uri.php$is_args$args;}
Scenario 1:
Assume that the URL visited by the user is: yuanhuaixuetang .com/aboutnginx server will first try to find the about file (relative to the website root directory), and if it exists, return the fileIf the about file does not exist, try to find about / directory (relative to the website root), returned if it exists.
If the about/ directory does not exist, try to find the about.php file (relative to the website root directory). If it exists, return the file and bring the subsequent request parameters according to the request information. In this example, the actual return is about .php, because the original request does not take parameters, so the actual return does not take parameters.If none of the above are found, you can return the corresponding error message according to the configuration in nginx.
Scenario 2:
Assume that the URL visited by the user is: yuanhuaixuetang.com/about?id=12
The parsing process of ginx is as follows:
The URL has passed parameters, ##is_args is "?", $args is id=12The parsing process is the same as above and will not be described in detail , what is actually returned to the user in this situation is: access the URL of the domain name about.php?id=12.
The above is the detailed content of How to hide .php in url. For more information, please follow other related articles on the PHP Chinese website!