首页 > 代码库 > [yii2]urlmanger
[yii2]urlmanger
首先配置下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. |
enableStrictParsing | Whether to enable strict parsing. |
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. |
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个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。