Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement case-insensitive url in thinkphp

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to achieve case-insensitivity in url in thinkphp". In daily operation, I believe that many people have doubts about how to achieve case-insensitivity in url in thinkphp. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve case-insensitivity in url in thinkphp". Next, please follow the editor to study!

In thinkphp, you can modify the parameters in "/ ThinkPHP/Conf/convention.php" so that url is case-insensitive and only needs to add "URL_CASE_INSENSITIVE=true" to the project configuration. Url is case-insensitive and does not change the naming convention.

This article operating environment: linux7.3 system, ThinkPHP5 version, Dell G3 computer.

Why is url in thinkphp not case-sensitive?

Thinkphp uses URL to locate module classes and execute operation methods. There is a problem here, that is, the case of URL. As we all know, under linux, it is very sensitive to case, that is, it is case-sensitive. However, php virtual hosts in linux support php code better than other operating systems (such as windows), while thinkphp's url is case-sensitive.

In order to avoid this contradiction of demand mode, how to sort out the url of thinkphp, which is the same as the ordinary cms system, without uppercase and lowercase zone classification?

For example, in a linux environment, it is normal for us to visit the following URL.

Http://www.yisu.com/index.php/User/add

But if we visit like this,

Http://www.yisu.com/index.php/user/add

There will be errors that do not exist in the module, because we define UserAction rather than userAction, so errors can occur in a case-sensitive loop, which can lead to a decline in the user experience. In fact, it is very simple for us to solve this problem, and the system provides us with a solution.

It is defined by configuration items, which are very important in this thinkphp.

You need to modify the configuration: / ThinkPHP/Conf/convention.php parameters:

We only need to add the following to the project configuration:

'URL_CASE_INSENSITIVE'= > true

In this way, URL is case-insensitive. One thing to note here is that if you define such a type of module class UserTypeAction, the module name is capitalized and accessed by underlining.

Http://www.51php.com/index.php/user_type/add

The case-insensitivity of URL does not change the naming convention of the system, and only by following the naming convention of the system can URL be implemented correctly.

At this point, the study of "how to achieve case-insensitivity in url in thinkphp" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report