This section: Details of thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation
one, URL rules
1, the default is to distinguish between uppercase and lowercase ,
2, suppose we do not want to distinguish between uppercase and lowercase to change the configuration file
' url_case_insensitive ' =>true,//url does not distinguish between uppercase and lowercase
* Module name too long:
A, assuming the module is named Usergroupaction, complex module (usually indexaction)
Then the URL to find the module is necessary to write
Http://localhost/thinkphp4/index.php/user_group/index
B, assuming ' url_case_insensitive ' =>false (to distinguish between uppercase and lowercase cases)
so the URL can also be written as
http://localhost/thinkphp4/ Index.php/usergroup/index
Second, URL pseudo-static (TP default support pseudo-static)
Http://localhost/thinkphp4/index.php/UserGroup/index.xml
* Default PDO, HTML, XML ... are supported. Suppose you want to limit the addition of a configuration
' Url_html_suffix ' = ' html|shtml|xml ',//limit pseudo-static suffix
third, URL routing
1. Start the route
To turn on routing support in the configuration file
' url_router_on ' = = true,//Turn on routing
2. Using routing
1. Rule Expressions Configure Routing
' url_router_on ' = = true,//Turn on routing
' Url_route_rules ' = Array (
' My ' = ' index/index ',//static address routing access Q: http://localhost/thinkphp/index.php/my
': Id/:num ' + ' index/index ', */* After the numeric value of random write, the letter will be OK
Dynamic Address Routing interview: http://localhost/thinkphp/index.php/10/200
Ability to pass a value or gain in a module controller using get
echo $_get[' id '];
echo $_get[' num '];
*/
' My/:num ' = ' index/index ',//mixed address routing http://localhost/thinkphp/index.php/my/200
' year/:year/:month/:d ate ' = ' index/index ',//dynamic and static mixed address routing: Http://localhost/thinkphp/index.php/ye Ar/2014/12/21
' year/:year\d/:month\d/:d ate\d ' = ' index/index ',//dynamic and static mixed address routing--plus the \D representative type can only be a number
' my/:id$ ' = ' index/index ',//plus $ description address can only be my/1000 behind no other content
);
2. Configuring routes in a regular form
Http://localhost/thinkphp/index.php/year/2014/12/21
'/^year\/(\d{4}) \ (\d{2})/(\d{2})/' = ' Index/index?
Year=:1&month=:2&date=:3 '
3. Precautions:
1. The more complex the route the more forward
' Url_route_rules ' =>array (
' my/:year/:month:/:d ay ' = ' index/day ', * Complex routes are placed in front of them and will not run on the back
' my/:id\d ' = ' index/index ',
' My/:name ' = ' index/index ',
)
2. Ability to use $ as a fully matched routing rule (regardless of complex no, will match all regular)
' Url_route_rules ' =>array (
' my/:id\d$ ' = ' index/index ',
' my/:name$ ' = ' index/index ',
' my/:year/:month:/:d ay$ ' = ' index/day ',
),
3. Using regular matching methods
' Url_route_rules ' =>array (
'/^my\/(\d+) $/' = ' index/index?id=:1 ',
'/^my\/(\w+) $/' = ' index/index?name=:1 ',
'/^my\/(\d{4}) \ (\d{2})/(\d{2}) $/' = ' index/day?year=:1&month=:2&day=:3 ',
),
iv. URL Rewriting
For example: http://localhost/thinkphp/index.php/Index/index.html/t/my----don't want index.php to appear
The following is the Apache configuration process, to be able to participate in the test:
1. The mod_rewrite.so module is loaded in the httpd.conf configuration file.
2. AllowOverride None Change None to all
3. Make sure Url_model is set to 2 (this step is omitted)
4. Save the following content as a. htaccess file under the sibling folder of the portal file
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]
</IfModule>
After restarting Apache, the original
Can be interviewed by
http://localhost/thinkphp/Index/index.html/t/my-simplified URL address, SEO support is better
v. URL generation(Manual has a specific introduction)
Public Function URL () {
echo U (' Index/add '); The URL address of the add operation that generated the index module
Thinkphp/index.php/index/add
}
thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation (15)