search
HomePHP FrameworkThinkPHPWhat should I do if thinkphp5 does not allow the .php suffix?

Recently, many ThinkPHP5 developers have reported that the system no longer allows the use of the .php suffix when setting up URL routing. This change has triggered heated discussions among netizens.

ThinkPHP is a mature and widely used PHP framework in China. Its simplicity, ease of use, rich functions, and excellent performance make it deeply loved by developers. However, in ThinkPHP 5.1.0 version, a major change is gradually getting into the eyes of developers: the system no longer allows the use of the .php suffix.

In fact, in the update log of version 5.1.0, the official has already explained this change. Specifically, when we set up URL routing, if the routing rule contains the .php suffix, the system will give the following prompt: The PHP suffix is ​​no longer supported.

This change has confused some developers who are accustomed to using the .php suffix. Why does ThinkPHP5 no longer support the .php suffix? The official explanation is that this is because the suffix of PHP, as a scripting language, does not match the structure of the URL access prefix, so it is not conducive to system retrieval and parsing. As more and more developers begin to use new API development methods such as RESTful API, it has become a trend to express the URL structure more simply and clearly. Therefore, support for the .php suffix has been canceled in version 5.1.0. .

So, how to set up URL routing in ThinkPHP5? Basically, we can still use PHP closures and other methods for routing settings. For example, we can set the following URL routing rules:

Route::rule('news/:id','index/news/read',['method'=>'get'],'',['id'=>'\d+']);

With this setting, when the user accesses the URL address /news/123, the system will automatically call the news method in the index controller, and the id in the parameter The value will be set to 123. Because there are no .php suffix constraints and there is no need to set Rewrite rules, developers only need to write the above code and then enter the corresponding URL address in the browser to perfectly display the relevant pages.

In short, although the removal of support for the .php suffix has disappointed old technology enthusiasts to a certain extent, judging from the overall performance of ThinkPHP5.1.0 version, this change may be more conducive to the speed of the system. Retrieval and analysis are also more in line with the trend of modern API development. Therefore, in order to better keep pace with the times and maintain the high performance and security of the system, we should actively adapt and apply this change during the development process.

The above is the detailed content of What should I do if thinkphp5 does not allow the .php suffix?. 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
What is the difference between think book and thinkpadWhat is the difference between think book and thinkpadMar 06, 2025 pm 02:16 PM

This article compares Lenovo's ThinkBook and ThinkPad laptop lines. ThinkPads prioritize durability and performance for professionals, while ThinkBooks offer a stylish, affordable option for everyday use. The key differences lie in build quality, p

How can I use ThinkPHP to build command-line applications?How can I use ThinkPHP to build command-line applications?Mar 12, 2025 pm 05:48 PM

This article demonstrates building command-line applications (CLIs) using ThinkPHP's CLI capabilities. It emphasizes best practices like modular design, dependency injection, and robust error handling, while highlighting common pitfalls such as insu

How to prevent SQL injection tutorialHow to prevent SQL injection tutorialMar 06, 2025 pm 02:10 PM

This article explains how to prevent SQL injection in ThinkPHP applications. It emphasizes using parameterized queries via ThinkPHP's query builder, avoiding direct SQL concatenation, and implementing robust input validation & sanitization. Ad

How to install the software developed by thinkphp How to install the tutorialHow to install the software developed by thinkphp How to install the tutorialMar 06, 2025 pm 02:09 PM

This article details ThinkPHP software installation, covering steps like downloading, extraction, database configuration, and permission verification. It addresses system requirements (PHP version, web server, database, extensions), common installat

What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture?What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture?Mar 18, 2025 pm 04:54 PM

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

How to deal with thinkphp vulnerability? How to deal with thinkphp vulnerabilityHow to deal with thinkphp vulnerability? How to deal with thinkphp vulnerabilityMar 06, 2025 pm 02:08 PM

This article addresses ThinkPHP vulnerabilities, emphasizing patching, prevention, and monitoring. It details handling specific vulnerabilities via updates, security patches, and code remediation. Proactive measures like secure configuration, input

How to fix thinkphp vulnerability How to deal with thinkphp vulnerabilityHow to fix thinkphp vulnerability How to deal with thinkphp vulnerabilityMar 06, 2025 pm 02:04 PM

This tutorial addresses common ThinkPHP vulnerabilities. It emphasizes regular updates, security scanners (RIPS, SonarQube, Snyk), manual code review, and penetration testing for identification and remediation. Preventative measures include secure

How to use thinkphp tutorialHow to use thinkphp tutorialMar 06, 2025 pm 02:11 PM

This article introduces ThinkPHP, a free, open-source PHP framework. It details ThinkPHP's MVC architecture, features (routing, database interaction), advantages (rapid development, ease of use), and disadvantages (potential over-engineering, commun

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

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.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!