search
HomeBackend DevelopmentPHP ProblemHow to remove php suffix in nginx

How to remove php suffix in nginx

Sep 29, 2020 am 09:41 AM
nginxphp

nginx method to remove the php suffix: first open the corresponding code file; then add the code statement as "location / {try_files $uri $uri/ $uri.php?$args;}".

How to remove php suffix in nginx

Recommended: "PHP Video Tutorial"

nginx rewrite hide .php suffix

I want to achieve the effect of hiding the suffix of http://xxx.com/post/abc.php, that is: http://xxx.com/post/abc. I searched a lot on the Internet but only hide the index. .php redirects to the entry file, who doesn’t know this, but this is 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;
}

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

The above is the detailed content of How to remove php suffix in nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.