This article is a summary of several types of ThinkPHP routing, namely common mode, PATHINFO, REWRITE and compatibility mode.

The official ThinkPHP documentation explains this in detail:

ThinkPHP supports four URL patterns: common, PATHINFO, REWRITE, and compatibility,

The URL_MODEL parameter can be set to change the URL schema.

Now let’s summarize the format of the four routes:

1. Common route (GET route)

htttp://localhost/? M = module name (group name) &c= controller name &a= method name &id=?Copy the code

2. Pathinfo Routing form (system default)

The route format is http://url/entry file/module name (group name)/controller name/method/Parameter name/Parameter value

For example: http://localhost/index.php/home/user/login/var/value/

3. REWRITE mode

The REWRITE pattern is an addition to the PATHINFO pattern to support rewriting rules that strip out urls

The entry file index.php in the address, but requires additional configuration of the WEB server rewrite rules.

If it is Apache, you need to add the. Htaccess file at the same level as the entry file, which contains the following contents:

<IfModule mod_rewrite.c>

 RewriteEngine on

 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteCond %{REQUEST_FILENAME} !-f

 RewriteRule ^(.*)$ index.php/The $1 [QSA,PT,L]

</IfModule>Copy the code

Next, can use the following URL to visit: http://localhost/home/user/login/var/value

4. Compatible routing modes

Compatibility mode is used for special environments that do not support PATHINFO.

Route format: http://url/import file? S =/ Module name (group name)/controller name/method name/Parameter name/Parameter value

Note: the little S here is the compatibility mode variable name, which can be changed through the configuration file.

This is a detailed summary of several types of ThinkPHP routing

To learn more, please visit:

Tencent T3-T4 standard boutique PHP architect tutorial directory directory, as long as you finish the guarantee salary rise a step (continue to update)


I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, YII2, Redis, Swoole, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc.