thinkphp URL code, URL pseudo-static, URL routing

Source: Internet
Author: User
thinkphp URL rules, url pseudo-static, URL routing

Thinkphp 3.1.2? URL rules, url pseudo-static, URL routing

First, URL rules

1, the URL by default is case-sensitive

2, if we do not want to distinguish between the case can change the configuration file

' Url_case_insensitive ' =>true,//value of true is a description URL is case-insensitive

3. If the module is named Usergroupaction

Then the URL to find the module is necessary to write

Http://localhost/thinkphp/index.php/user_group/index

4, if ' url_case_insensitive ' =>false? Case sensitive

Then the URL can also be written as

Http://localhost/thinkphp/index.php/UserGroup/index

Second, the URL pseudo-static

' 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,

? ? ? ? ? ? ? ? and configure the ' url_route_rules ' parameter

?

2. Using routing

1. Rule Expressions Configure Routing

' My ' = ' index/index ',//static address routing

': id/:num ' = ' index/index ',//dynamic address Routing

' year/:year/:month/:d ate ' = ' index/index ',//dynamic and static mixed address routing

' year/:year\d/:month\d/:d ate\d ' = ' index/index ',//dynamic and static mixed address routing?

Plus the \D representative type can only be numeric

' my/:id$ ' = ' index/index ',//plus $ description address can only be my/1000 behind cannot have other content

2. Regular expression Configuration routing

'/^year\/(\d{4}) \ (\d{2})/(\d{2})/' = ' index/index?year=:1&month=:2&date=:3 '

3. Precautions:

1. More complex routes to the front, or cause URL parsing confusion

' Url_route_rules ' =>array (

' my/:year/:month:/:d ay ' = ' index/day ',

' my/:id\d ' = ' index/index ',

' My/:name ' = ' index/index ',

)

2. You can use the route rule as an exact match, indicating that it ends and cannot be followed by other parameters

' 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 ',

),

?

?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.