Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement case-insensitive url in thinkphp

Shulou Source: shulou.com Published: 2022-06-01 01:15:24 10月05日 Update

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!

Tags: Size system problem configuration module learning that is environment parameters to uppercase lowercase way method more project help practical ordinary important contradictory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Redmi macOS Shulou Technology Huawei