A Brief analysis of pathinfo mode and URL rewriting in ThinkPHP

  • 2020-12-07 03:59:30
  • OfStack


http://serverName/appName/module/action/id/1/

This is the pathinfo pattern

Without regard to routing, the first parameter is resolved into the module name (recursively, if grouping is enabled), and the second parameter is resolved into an operation, which is passed explicitly and must come in pairs, for example:


http://serverName/appName/module/action/year/2008/month/09/day/21/

URL usually contains ES13en.php. To achieve better SEO effect, index.php in URL may need to be removed. This effect can be achieved by URL rewriting, which usually requires the server to open the URL_REWRITE module.
The configuration process of Apache is as follows:
1. mod_rewrite.so module is loaded in httpd.conf configuration file
2. AllowOverride None Change None to All
3. Make sure URL_MODEL is set to 2
4. Save the following file as.htaccess and put it in the same sibling of the entry file


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

For re did not contact.htacces file can baidu 1 some, here to remind 1, save the file name is.htaccess, may look like only suffix, that is, do not add in front of a ***.htaccess.

After restarting Apache, the original
http://serverName/index.php/Blog/read/id/1
You can access it
http://serverName/Blog/read/id/1
Simplified URL address


Related articles: