Ways to Enable ThinkPHP to Support Upper and Lower url Address Access

  • 2021-07-22 09:19:41
  • OfStack

This article illustrates a way to enable thinkphp to support upper and lower case url address access. Share it for your reference. The specific implementation method is as follows:

Usually, ThinkPHP distinguishes case url by default, which is also two different names from linux system 1 in lowercase url, but we are used to thinking of case 1 when using windows, so we should deal with the problem according to the user's habits. Let's look at the solution to the problem.

The case recognition function of thinkphp is turned on in the configuration file, so that the link case can be accessed normally:
'URL_CASE_INSENSITIVE' = > true
File naming is canonical, but when you use __URL__ in the template to get the current url path, you don't get url correctly.
The manual reads as follows:
There is one thing to note here. If we define a module class of UserTypeAction, the access of URL should be:
http://serverName/index.php/user_type/list
Instead of
http://serverName/index.php/usertype/list
Using __URL__ in the template yields the same link as below, without underlining it.
This problem has also received a lot of feedback on the Internet. One solution is to modify the source code of tp:
In the Dispatcher. class. php file under the Core folder of the Lib folder of tp, find line 181, which defines how to get the address of __URL__:

$moduleName = defined('MODULE_ALIAS')?MODULE_ALIAS:MODULE_NAME;
if(defined('GROUP_NAME')) {
    define('__URL__',!empty($domainModule)?__GROUP__.$depr : __GROUP__.$depr.( C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName ) );
}else{
    define('__URL__',!empty($domainModule)?__APP__.'/' : __APP__.'/'.( C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName) );
}

Put one of them
C('URL_CASE_INSENSITIVE') ? strtolower($moduleName) : $moduleName )
Change to:
C('URL_CASE_INSENSITIVE')?parse_name($moduleName,0):$moduleName 

Then the problem will be solved!

I hope this article is helpful to everyone's ThinkPHP framework programming.


Related articles: