ThinkPHP URL規則、URL偽靜態、URL路由

來源:互聯網
上載者:User
ThinkPHP URL規則、URL偽靜態、URL路由

ThinkPHP 3.1.2?URL規則、URL偽靜態、URL路由

一、URL規則

1、URL預設是區分大小寫

2、如果我們不想區分大小寫可以改設定檔

'URL_CASE_INSENSITIVE'=>true,//值為true是說明url不區分大小寫

3、如果模組名為 UserGroupAction

那麼url找模組就必要要寫成

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

4、如果'URL_CASE_INSENSITIVE'=>false ? //區分大小寫

那麼url也可以寫為

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

二、URL偽靜態

'URL_HTML_SUFFIX'=>'html|shtml|xml',//限制偽靜態尾碼

三、URL路由

1、啟動路由

要在設定檔中開啟路由支援

? ? ? ? ? ? ? ? 'URL_ROUTER_ON'=>true,

? ? ? ? ? ? ? ? 並配置'URL_ROUTE_RULES'參數

?

2、使用路由

1.規則運算式配置路由

'my'=>'Index/index',//靜態地址路由

':id/:num'=>'Index/index',//動態地址路由

'year/:year/:month/:date'=>'Index/index',//動態和靜態混合地址路由

'year/:year\d/:month\d/:date\d'=>'Index/index',//動態和靜態混合地址路由?

加上 \d代表類型只能是數字

'my/:id$'=>'Index/index',// 加上$說明地址中只能是 my/1000 後面不能有其他內容

2.Regex配置路由

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

3、注意事項:

1.越複雜的路由越往前面放,否則造成url解析混亂

'URL_ROUTE_RULES'=>array(

'my/:year/:month:/:day'=>'Index/day',

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

'my/:name'=>'Index/index',

)

2.可以使用$作為完全符合的路由規則,表示以此結束,其後不能跟其他參數

'URL_ROUTE_RULES'=>array(

'my/:id\d$'=>'Index/index',

'my/:name$'=>'Index/index',

'my/:year/:month:/:day$'=>'Index/day',

),

3.用正則匹配的方式

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

),

?

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.