thinkphp URL Routing rules and configuration examples, thinkphpurl_php tutorial

Source: Internet
Author: User

thinkphp URL Routing rules and Configuration instances, Thinkphpurl


This paper describes the URL routing rules and configuration method of thinkphp. Share to everyone for your reference. The specific analysis is as follows:

First, URL rules

1, the default is case-sensitive

2, if we do not want to distinguish between the case can change the configuration file
Copy the code as follows: ' url_case_insensitive ' =>true,//url case insensitive
3, if the module name is usergroupaction, then the URL to find the module is necessary to write
Copy the Code code as follows: Http://localhost/thinkphp4/index.php/user_group/index

4, if ' url_case_insensitive ' =>false, then the URL can also be written as
Copy the Code code as follows: Http://localhost/thinkphp4/index.php/UserGroup/index

Second, the URL pseudo-static
Copy the code as follows: ' 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
Copy the Code Code as follows: ' url_router_on ' =>ture//open route

2. Using routing

1. Rule Expressions Configure Routing
Copy the Code Code as follows: ' Url_route_rules ' =>array ()//Routing rule
' My ' = ' index/index ',//static address routing
' My ' = '/index/index ',//static address routing, plus/skip directly to the root directory of the Web site.
': id/:num ' = ' index/index ',//dynamic address routing, can $_get receive address bar parameters
' 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 \d representative type can only be numeric
' my/:id$ ' = ' index/index ',//plus $ Description The address can only be my/1000 there's nothing else left behind.
2. Regular expression configuration routing, must start/end
Copy the code as follows: '/^year\/(\d{4})/(\d{2})/(\d{2})/' = = ' index/index?year=:1&month=:2&date=:3 '//here \ D means must be a number

3. Precautions:

1. The more complex the route the more forward
Copy the Code Code as follows: ' 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
Copy the Code Code as follows: ' Url_route_rules ' =>array (
' my/:id\d$ ' = ' index/index ',
' my/:name$ ' = ' index/index ',
' my/:year/:month:/:d ay$ ' = ' index/day ',
),
3. Start with/^ and end with $/in regular match mode
Copy the Code Code as follows: ' 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 ',
),

I hope this article will be helpful to everyone's thinkphp construction station.

http://www.bkjia.com/PHPjc/917675.html www.bkjia.com true http://www.bkjia.com/PHPjc/917675.html techarticle thinkphp URL Routing rules and Configuration instances, Thinkphpurl This article describes the thinkphp URL routing rules and Configuration methods. Share to everyone for your reference. The specific analysis is as follows: one 、...

  • 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.