Four URL modes of ThinkPHP: URL_MODEL

Source: Internet
Author: User
: This article mainly introduces ThinkPHP's four URL modes URL_MODEL. if you are interested in PHP tutorials, refer to it. ThinkPHP supports four URL modes, which can be defined by setting the URL_MODEL parameter, including the 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 (default mode)
The URL_PATHINFO mode is used by default. the PATHINFO mode also includes the normal mode and the smart mode:
PATHINFO normal mode: 'Path _ model' => 1,
The URL parameters in this mode are not ordered, 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 (default mode)
This mode automatically identifies modules and operations, such
Http: // serverName/appName/module/action/id/1/
Http: // serverName/appName/module, action, id, 1/
In intelligent mode, the first parameter is parsed into a module name (or a route name, which is described below ), the second parameter is parsed into an operation (if the first parameter is not the route name), the following parameters are explicitly transmitted and must appear in pairs. for example:
Http: // serverName/appName/module/action/year/2000/month/01/day/01/
The delimiter between parameters is set by the PATH_DEPR parameter. the default value is "/". if PATH_DEPR is set to "^ ",
Http: // serverName/appName/module ^ action ^ id ^ 1/
Do not use the "@" and "&" symbols to separate them. This symbol has special purposes and may cause other conflicts.
If you want to simplify the URL format, you can use the routing function (which will be described later). in PATHINFO mode, related parameters are converted to GET variables and incorporated into REQUEST variables, therefore, it does not prevent the above variables from being obtained in the application.
3. REWRITE mode: 'URL _ model' => 2,
The URL mode has the same functions as the PATHINFO mode, except that you do not need to write an entry file in the URL or define a. 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,
The compatibility mode is the combination of the common mode and PATHINFO mode, and allows the application to directly switch to the PATHINFO mode as needed without changing the template and program. Basically, it supports any runtime environment.
You only need to pass in PATHINFO compatibility mode to obtain the variable VAR_PATHINFO. the default value is s. for example:
Http: // serverName/appName /? S =/module/action/id/1/
The operation is equivalent to the above URL, and the parameter delimiter definition can also be supported. for example, when PATH_DEPR is set "~ ", The following URL is valid:
Http: // serverName/appName /? S = module ~ Action ~ Id ~ 1
In compatibility mode, the following template files do not need to be changed. keep the same method as PATHINFO. you only need to clear the template cache directory when switching the URL mode.

The above introduces ThinkPHP's four URL modes URL_MODEL, including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.