Home Backend Development PHP Problem How to hide .php in url

How to hide .php in url

Aug 26, 2020 am 09:35 AM
nginx

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

How to allow external network access to tomcat server

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

What are the nginx start and stop commands?

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

What are the differences between tomcat and nginx What are the differences between tomcat and nginx Dec 27, 2023 pm 05:07 PM

What are the differences between tomcat and nginx

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

Welcome to nginx!How to solve it?

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

How to register phpmyadmin

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

How to deploy nodejs project to server

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

How to solve the problem of nginx when accessing the website

See all articles