ThinkPHPURL rules, URL pseudo-static, URL routing ThinkPHP3.1.2? URL rules, URL pseudo-static, URL routing I. URL rules 1. the URL is case-sensitive by default. 2. if you do not want to distinguish the case, you can change the configuration file 'URL _ CASE_INSENSITIVE '= & gt; true, // if the value is true, the url is not ThinkPHP URL rules, URL pseudo-static, URL routing
ThinkPHP 3.1.2? URL rules, URL pseudo-static, URL routing
I. URL rules
1. URLs are case sensitive by default.
2. you can change the configuration file if you do not want to be case sensitive.
'URL _ CASE_INSENSITIVE '=> true, // if the value is true, the URL is case insensitive.
3. if the module name is UserGroupAction
Then, you need to write the url module
Http: // localhost/thinkphp/index. php/user_group/index
4. if 'URL _ CASE_INSENSITIVE '=> false? // Case sensitive
The url can also be written
Http: // localhost/thinkphp/index. php/UserGroup/index
II. URL pseudo-static
'URL _ HTML_SUFFIX '=> 'HTML | shtml | XML', // restrict pseudo-static suffixes
III. URL routing
1. start the route
To enable route support in the configuration file
? ? ? ? ? ? ? ? 'URL _ ROUTER_ON '=> true,
? ? ? ? ? ? ? ? Configure the 'URL _ ROUTE_RULES 'parameter.
?
2. use routing
1. configure routes using rule expressions
'My => 'index/Index', // static address routing
': Id/: num' => 'index/Index', // dynamic address routing
'Year/: year/: month/: date' => 'index/Index', // dynamic and static hybrid address routing
'Year/: year \ d/: month \ d/: date \ d' => 'index/Index', // dynamic and static hybrid address routing?
Add \ d to indicate that the type can only be numbers
'My/: id $ '=> 'index/Index', // add $ to indicate that the address must be followed by my/1000 and cannot contain any other content.
2. configure routes using regular expressions
'/^ Year \/(\ d {4}) \/(\ d {2}) \/(\ d {2})/' => 'index/Index? Year =: 1 & month =: 2 & date =: 3'
3. notes:
1. the more complex the route is, the more advanced the route is. Otherwise, the url parsing will be chaotic.
'URL _ ROUTE_RULES '=> array (
'My/: year/: month:/: day' => 'index/Day ',
'My/: id \ d' => 'index/Index ',
'My/: name' => 'index/Index ',
)
2. you can use $ as a completely matched routing rule to end the process. it cannot be followed by other parameters.
'URL _ ROUTE_RULES '=> array (
'My/: id \ d $ '=> 'index/Index ',
'My/: name $ '=> 'index/Index ',
'My/: year/: month: //: day $ '=> 'index/Day ',
),
3. Regular Expression Matching
'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 ',
),
?
?