How to hide .php in url

藏色散人
Release: 2023-03-05 08:38:02
Original
2752 people have browsed it

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.

How to hide .php in url

# Recommended: "

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.


How to hide .php in urlEasy to use nginx’s try_files directive.

Add a configuration sentence in your nginx configuration file (nginx.conf):

location / {ttry_files $uri $uri/ $uri.php$is_args$args;}
Copy after login

to hide the .php suffix name of the web page.

try_files is an instruction in nginx, somewhat similar to rewrite, which is used to try to find the file or directory with the path specified after the instruction and return it.

$uri represents the URI path of the current request, which is the path behind the URL domain name, without parameters.

$ is_args means that if there are parameters in the requested URL, $is_args represents "?". If there are no parameters in the requested URL, an empty string will be returned for parameter passing.

$args represents the complete parameters in the request URL.

The following is an explanation of how the nginx server handles it based on the example in the figure:

Scenario 1:

Assume that the URL visited by the user is: yuanhuaixuetang .com/about


How to hide .php in url

nginx’s parsing process is as follows:

The URL does not pass parameters,

uri is /about,uri is/about, nginx 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, uriis/about,uri is/about, ##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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template