Thinkphp Learning Note (vi) URL pattern

Source: Internet
Author: User
Tags naming convention

1.URL case

The URL of the thinkphp framework is case-sensitive (mainly for modules, controllers, and operation names, excluding application parameters), which is critical because the thinkphp naming convention is a rule that uses the Hump method (capitalized), and the modules and controllers in the URL are the corresponding files. Therefore, there must be a case-sensitive problem under the Linux environment.

The framework has a built-in configuration parameter to address the case of the URL, as follows:

' Url_case_insensitive ' =>true,

When URL_CASE_INSENSITIVE set to True indicates that the URL address is not case sensitive, this is the default setting for the framework under Deployment mode.

When debugging mode is turned on, this parameter is false, so you will find that the URL is case-sensitive under debug mode.

2.URL mode

If we access the portal file directly, the default action (index) of the default controller (index) under the default module (Home) is accessed because there are no modules, controllers, and actions in the URL, so the following access is equivalent:

http://serverName/index.php
Http://serverName/index.php/Home/Index/index

This kind of URL pattern is the system default PathInfo mode, different URL pattern obtains the module and the operation method is different, the thinkphp supports the URL pattern to have four kinds: Normal mode, PATHINFO, rewrite, and compatibility modes , you can set Url_model parameter changes the URL pattern.

/p>

url mode BR style= "Text-indent:2em;text-align:left;" > url_model settings
0
pathinfo mode

1

rewrite mode 2
Tolerance mode
3

If you complete the application of the following modules in a unified URL pattern, you can set the URL pattern in the application configuration file, if different modules need to set a different URL pattern, you can set in the module configuration file.

3. Normal mode

The Normal mode is the traditional get pass method to specify the modules and operations that are currently accessed, such as:

http://localhost/?m=home&c=user&a=login&var=value

The M parameter represents the module, the C parameter represents the controller, the A parameter represents the operation (of course these parameters are configurable), and the other get parameters are later represented.

If the default variable settings conflict with your application variables, you will need to reset the system configuration, for example, to the following:

' Var_module ' = ' module ',//default module get variable
' Var_controller ' = ' controllers ',//default controller gets variable
' Var_action ' = ' action ',//default action get variable

The above access address becomes:http://localhost/?module=home&controller=user&action=login&var=value

Note that var_module can only be set in the app configuration file, and other parameters can be set in the module configuration as well.

4.PATHINFO mode

pathinfo mode is the default URL mode of the system, provides the best SEO support, the system has already done the environment compatibility processing, so can support most host environment. Corresponding to the URL pattern above, the URL access address under PathInfo mode is:http://localhost/index.php/home/user/login/var/value/

The first three parameters of the PathInfo address represent module/controller/operation respectively.

However, under the PathInfo mode, you can still use the normal URL pattern of the parameter mode, for example http://localhost/index.php/home/user/login?var=value is still valid.

Under PathInfo mode, URLs are customizable, for example, through the following configuration:

We can also support the following URL access:http://localhost/index.php/home-user-login-var-value

5.REWRITE mode

Rewrite mode is based on the PathInfo mode to add the support of rewrite rules, you can remove the URL address inside the portal file index.php, but need to configure additional Web server rewrite rules.

If it is Apache, you will need to add the. htaccess file to the sibling of the portal file with the following content:





Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]
</IfModule>

Next, you can access it using the following URL address:http://localhost/home/user/login/var/value

URL rewriting for more environments supports URL rewriting in the Reference deployment section

6. Compatibility mode

compatibility mode is used for special environments that do not support pathinfo, and the URL address is:http://localhost/?s=/home/user/login/var/value

You can change the name definition of a compatible mode variable, for example:

' Var_pathinfo ' = ' PATHINFO '

The PathInfo parameter delimiter is still valid for compatibility mode, for example:

With the above configuration, the URL access address can be changed to:http://localhost/?s=/home-user-login-var-value

Compatibility mode, in conjunction with the definition of a Web server rewrite rule, can achieve the same URL effect as rewrite mode.

For example, if we are under Apache, the. htaccess file is changed to the following:




Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ index.php?s=/$1 [qsa,pt,l]
</IfModule>

You can access the following URL address in the same way as the rewrite mode:http://localhost/home/user/login/var/value



This article is from the "Little Prince" blog, please be sure to keep this source http://littleprince.blog.51cto.com/1491292/1618052

Thinkphp Learning Note (vi) URL pattern

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.