URL Request
Thinkphp uses a single-entry mode to access the app, directing all requests to the app to the app's portal file, which resolves the currently requested module, controller, and operation from the URL parameters, and a standard URL access format:
http://serverName/index.php/模块/控制器/操作
If we directly access the portal file, because there is no module, controller and operation in the URL,
Therefore, the default action (index) of the default controller (index) under the default module (Home) is accessed,
Therefore, the following access is equivalent:
http://serverName/index.phphttp://serverName/index.php/Home/Index/index
This URL pattern is the system default PathInfo mode,
Different URL patterns get the module and the method of operation is different,
Thinkphp supports four types of URL patterns: normal mode, PATHINFO, rewrite, and compatibility mode .
1 Normal Mode
The normal mode is to use the traditional get Pass method to specify the modules, controllers, and operations that are currently accessed, such as:
http://localhost/?m=home&c=index&a=hello&name=thinkphp
The M parameter represents the module, C represents the controller, and a represents the operation (of course, these parameter names are configurable), followed by other get parameters.
The default value can not be passed, so the following URL access is equivalent to the above:
http://localhost/?a=hello&name=thinkphp
2 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/index/hello/name/thinkphp/
The first three parameters of the PathInfo address represent module/controller/operation respectively.
Under PathInfo mode, you can also pass in parameters in normal mode, for example:
http://localhost/index.php/home/index/hello?name=thinkphp
Under PathInfo mode, the URL parameter delimiter is customizable, for example, through the following configuration:
‘URL_PATHINFO_DEPR‘=>‘-‘,// 更改PATHINFO参数分隔符
We can support the following URL access:
http://localhost/index.php/home-index-hello-name-thinkphp
3 Rewrite mode
Rewrite mode is based on the PathInfo mode to add support for rewrite rules, you can remove the URL address inside the entry 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:
<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>
Next, you can use the following URL address to access the
http://localhost/home/index/hello/name/thinkphp/
4 Compatibility Mode
Compatibility mode is used for special environments that do not support pathinfo, and the URL address is:
http://localhost/?s=/home/index/hello/name/thinkphp
Compatibility mode, in conjunction with the definition of a Web server rewrite rule, can achieve the same URL effect as rewrite mode.
Thinkphp_ Basic (2) URL pattern