thinkphp Four URL patterns Url_model

Source: Internet
Author: User
The thinkphp supports four URL patterns that can be defined by setting the Url_model parameter, including normal mode, PATHINFO, rewrite, and compatibility mode.
1. Normal mode: ' Url_model ' =>0,
Http://serverName/appName/?m=module&a=action&id=1
2.PATHINFO mode: ' Url_model ' =>1, (system default mode)
Using the Url_pathinfo mode by default, the PathInfo mode also includes both normal and smart modes:
PathInfo Normal mode: ' Path_model ' =>1,
The mode URL parameter has no order, for example
Http://serverName/appName/m/module/a/action/id/1
Http://serverName/appName/a/action/id/1/m/module
PathInfo Smart mode: ' Path_model ' =>2, (system default mode)
This mode automatically identifies modules and operations, such as
http://serverName/appName/module/action/id/1/
http://serverName/appName/module,action,id,1/
In smart mode, the first parameter is parsed into the module name (or the route name, as described below), the second parameter is parsed into the operation (the first parameter is not the name of the route), the subsequent arguments are passed explicitly, and must appear in pairs, for example:
http://serverName/appName/module/action/year/2000/month/01/day/01/
Where the delimiter between the parameters is set by the PATH_DEPR parameter, the default is "/", if the setting of Path_depr is "^", then
http://servername/appname/module^action^id^1/
Note that you do not use the "@" and "&" symbols for a special purpose and may cause other conflicts.
If you want to simplify the form of a URL through the routing function (described later), in the PathInfo mode, the relevant parameters will be converted to get variables, as well as the request variable, so it does not hinder the application of the above variables to get.
3.REWRITE mode: ' Url_model ' =>2,
The URL pattern is the same as the PathInfo mode function, except that it is not necessary to write the portal file in the URL, and can define the. htaccess file.
For example, we can add the following. htaccess content to point all operations to the index.php file.
Rewriteengine on
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]
4. Compatibility mode: ' Url_model ' =>3,
Compatibility mode is a combination of normal mode and PathInfo mode, and allows the application to switch directly to PathInfo mode when needed without having to change the templates and programs, basically supporting any operating environment.
Only need to pass in PATHINFO compatibility mode to get the variable var_pathinfo, the default value is s, for example
http://serverName/appName/?s=/module/action/id/1/
Performs the equivalent of the above URL, and can also support the definition of a parameter split symbol, such as in the case where Path_depr is set to "~", the following URL is valid:
Http://serverName/appName/?s=module~action~id~1
In the case of compatibility mode, the template file does not have to make any changes, keep the same as the PathInfo mode, only need to clear the template cache directory when switching the URL mode.

The above describes the thinkphp of the four kinds of URL pattern Url_model, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.