Home > Backend Development > PHP Problem > How to remove .php suffix from nginx

How to remove .php suffix from nginx

藏色散人
Release: 2023-03-01 20:52:02
Original
3333 people have browsed it

How to remove ".php" from nginx: first find and open the corresponding nginx file; then modify the code to "location / {try_files $uri $uri/ $uri.php?$args;}"; finally save This file will do.

How to remove .php suffix from nginx

nginx rewrite hide .php suffix

I want to achieve http://xxx.com/ The effect of hiding the suffix of post/abc.php is: http://xxx.com/post/abc. I searched a lot on the Internet and all of them just hide index.php and redirect it to the entry file. Who doesn't know this? But this Not what I want. Then some people said that nginx is not good and can only use apache. However, I only made slight changes and everything moved so smoothly, which was exactly the effect I wanted!

It’s actually very simple, just one line of code

location / {
    try_files $uri $uri/ $uri.php?$args;
}
Copy after login

Now the access effect of the following two sets of URLs is the same

before:
http://abc.com/login.php
http://abc.com/register.php
http://abc.com/blog/post.php
http://abc.com/xxx/xxx/anything.php
after:
http://abc.com/login
http://abc.com/register
http://abc.com/blog/post
http://abc.com/xxx/xxx/anything
Copy after login

Recommended: "PHP Tutorial

The above is the detailed content of How to remove .php suffix from nginx. 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