Enable ThinkPHP to support access using case-insensitive URLs

Source: Internet
Author: User
This article mainly introduces how to enable ThinkPHP to support access by case-sensitive URLs. it is a very useful technique for developing ThinkPHP programs in Windows. if you need ThinkPHP, refer to ThinkPHP.

This example describes how to enable thinkphp to support access with case-insensitive URLs. Share it with you for your reference. The specific implementation method is as follows:

Generally, ThinkPHP uses URLs of different upper and lower cases by default. this is the same as that of linux systems. two different names are available in lower case URLs. However, we use windows to consider ThinkPHP as case-sensitive, therefore, we still need to solve the problem according to user habits. let's take a look at the solution.

The thinkphp case sensitivity function is enabled in the configuration file so that all links can be accessed normally:
'URL _ CASE_INSENSITIVE '=> true
The file names are standard, but the url is not obtained correctly when/index. php/Article is used in the template to obtain the current url path.
Write the following in the manual:
Note that if we define a module class of UserTypeAction, the URL access should be:
Http: // serverName/index. php/user_type/list
Instead
Http: // serverName/index. php/usertype/list
The link obtained by using/index. php/Article in the template is still the one below, and there is no underline.
Many people have reported this problem on the internet. the solution is to modify the source code of tp:
In the Dispatcher. class. php file in the Core folder of the Lib folder of tp, locate row 181. the address acquisition method of/index. php/Article is defined here:

The code is as follows:

$ ModuleName = defined ('Module _ alias ')? MODULE_ALIAS: MODULE_NAME;
If (defined ('group _ name ')){
Define ('/index. php/article ',! Empty ($ domainModule )? /Index. php. $ depr:/index. php. $ depr. (C ('URL _ CASE_INSENSITIVE ')? Strtolower ($ moduleName): $ moduleName ));
} Else {
Define ('/index. php/article ',! Empty ($ domainModule )? /Index. php. '/':/index. php. '/'. (C ('URL _ CASE_INSENSITIVE ')? Strtolower ($ moduleName): $ moduleName ));
}


Put

The code is as follows:

C ('URL _ CASE_INSENSITIVE ')? Strtolower ($ moduleName): $ moduleName)

Changed:

The code is as follows:

C ('URL _ CASE_INSENSITIVE ')? Parse_name ($ moduleName, 0): $ moduleName


The problem is solved!

I hope this article will help you with ThinkPHP framework programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.