[yii2]urlmanger

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   ar   使用   for   sp   

首先配置下nginx,確保可以不使用index.php來訪問

server{    listen      8082;    server_name yii2.dev;    access_log logs/yii2.access.log;    error_log logs/yii2.error.log error;    root /home/admin/web/nginx/html/basic/web/;    location / {            index  index.html index.php;            if (!-e $request_filename){                rewrite ^/(.*) /index.php?r=$1 last;            }    }

APP中配置config

‘urlManager‘ => [            ‘enablePrettyUrl‘ => true,             ‘enableStrictParsing‘ => false,            ‘showScriptName‘ => false,            ‘rules‘ => [                ‘<module:\w+>/<controller:\w+>/<id:\d+>‘ => ‘<module>/<controller>/view‘,                ‘<controller:\w+>/<id:\d+>‘ => ‘<controller>/view‘,            ],        ]

其中KEY的說明

enablePrettyUrl
Whether to enable pretty URLs. 
Instead of putting all parameters in the query string part of a URL,
pretty URLs allow using path info to represent some of the parameters and can thus produce more user-friendly URLs,
such as "/news/Yii-is-released", instead of "/index.php?r=news/view&id=100".
enableStrictParsing
Whether to enable strict parsing. 
If strict parsing is enabled, the incoming requested URL must match at least one of the $rules in order to be treated as a valid request.
Otherwise, the path info part of the request will be treated as the requested route. This property is used only when $enablePrettyUrl is true.
showScriptName
Whether to show entry script name in the constructed URL. Defaults to true. This property is used only if $enablePrettyUrl is true.
rules
The rules for creating and parsing URLs when $enablePrettyUrl is true. This property is used only if $enablePrettyUrl is true.
Each element in the array is the configuration array for creating a single URL rule.
The configuration will be merged with $ruleConfig first before it is used for creating the rule object.
enableStrictParsing,showScriptName,rules 要生效必須設定enablePrettyUrl=true.
因此要使rules配置的規則生效,需要首先設定enablePrettyUrl=true.設定完成以後按照映射規則訪問。
http://yii2.dev:8082/admin/default/1 其中Module:admin controller:default action:view id:1 符合規則:‘<module:\w+>/<controller:\w+>/<id:\d+>‘ => ‘<module>/<controller>/view‘,



[yii2]urlmanger

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.