Home > Backend Development > PHP Tutorial > ThinkPHP's four URL modes URL_MODEL

ThinkPHP's four URL modes URL_MODEL

WBOY
Release: 2016-07-29 08:59:39
Original
1084 people have browsed it

ThinkPHP supports four URL modes, which 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 )
Use URL_PATHINFO mode by default. PATHINFO mode also includes normal mode and smart mode:
PATHINFO normal mode: 'PATH_MODEL'=>1,
This mode URL parameters have 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, page One parameter will be parsed into a module name (or route name, described below), the second parameter will be parsed into an operation (provided the first parameter is not a route name), and subsequent parameters are passed explicitly , and must appear in pairs, for example:
http://serverName/appName/module/action/year/2000/month/01/day/01/
The separator between parameters is set by the PATH_DEPR parameter, and the default is "/", if PATH_DEPR is set to "^", then
http://serverName/appName/module^action^id^1/
Be careful not to use the "@" and "&" symbols for separation. This symbol has special purposes , may cause other conflicts.
If you want to simplify the form of the URL, you can use the routing function (described later). In PATHINFO mode, the relevant parameters will be converted into GET variables and incorporated into the REQUEST variables, so it will not hinder the acquisition of the above variables in the application.
3.REWRITE mode: 'URL_MODEL'=>2,
This URL mode has the same function as the PATHINFO mode, except that there is no need to write an entry file in the URL, and .htaccess files can be defined.
For example, we can add the following .htaccess content to direct 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 applications to directly switch to PATHINFO mode when needed without changing templates and programs. It can basically support any operating 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/
will perform operations equivalent to the above URL. , and can also support the definition of parameter separation symbols. For example, when PATH_DEPR is set to "~", the following URL is valid:
http://serverName/appName/?s=module~action~id~1
Compatibility mode In this case, there is no need to make any changes to the template file. It remains the same as the PATHINFO mode. You only need to clear the template cache directory when switching the URL mode.

The above introduces the four URL modes URL_MODEL of ThinkPHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template