首先配置下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的更多相关文章

  1. Yii2的深入学习--行为Behavior

    我们先来看下行为在 Yii2 中的使用,如下内容摘自 Yii2中文文档 行为是 [[yii\base\Behavior]] 或其子类的实例.行为,也称为 mixins,可以无须改变类继承关系即可增强一 ...

  2. 网站实现微信登录之回调函数中登录逻辑的处理--基于yii2开发的描述

    上一篇文章网站实现微信登录之嵌入二维码中描述了如何在自己的登录页面内嵌入登录二维码,今天的这篇文章主要是描述下在扫码成功之后微信重定向回网站后登录逻辑的处理,其实也就是验证身份信息,授权用户登录的逻辑 ...

  3. 网站实现微信登录之嵌入二维码——基于yii2开发的描述

    之前写了一篇yii2获取登录前的页面url地址的文章,然后发现自己对于网站实现微信扫码登录功能的实现不是很熟悉,所以,我会写2-3篇的文章来描述下一个站点如何实现微信扫码登录的功能,来复习下微信扫码登 ...

  4. yii2获取登录前的页面url地址--电脑和微信浏览器上的实现以及yii2相关源码的学习

    对于一个有登录限制(权限限制)的网站,用户输入身份验证信息以后,验证成功后跳转到登录前的页面是一项很人性化的功能.那么获取登录前的页面地址就很关键,今天在做一个yii2项目的登录调试时发现了一些很有意 ...

  5. 记一次nginx部署yii2项目时502 bad gateway错误的排查

    周六闲来无事,就试着安装和部署下yii2,安装过程没什么问题,但部署到nginx上时遇到了502 bad gatewary问题,折腾了半天才搞定.这个问题是我以前在部署yii2时没有遇到过的,因此记在 ...

  6. yii2的权限管理系统RBAC简单介绍

    这里有几个概念 权限: 指用户是否可以执行哪些操作,如:编辑.发布.查看回帖 角色 比如:VIP用户组, 高级会员组,中级会员组,初级会员组 VIP用户组:发帖.回帖.删帖.浏览权限 高级会员组:发帖 ...

  7. yii2 RESTful api的详细使用

    作者:白狼 出处:http://www.manks.top/yii2-restful-api.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则 ...

  8. yii2 ActiveRecord多表关联以及多表关联搜索的实现

    作者:白狼 出处:http://www.manks.top/yii2_many_ar_relation_search.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明 ...

  9. yii2权限控制rbac之rule详细讲解

    作者:白狼 出处:http://www.manks.top/yii2_rbac_rule.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留 ...

随机推荐

  1. 洛谷—— P3395 路障

    https://www.luogu.org/problem/show?pid=3395 题目背景 此题约为NOIP提高组Day1T1难度. 题目描述 B君站在一个n*n的棋盘上.最开始,B君站在(1, ...

  2. 同一页面引入多个JS文件的编码问题

    原来只是觉得IE解析HTML文件的时候,需要知道其传输编码,才能正确处理,而从来没有在意过JavaScript文件的编码问题.结果今天发现同一页面中的多个JavaScript文件如果保存编码不同,也会 ...

  3. 通过BSSID和无线流量传输后门Payload

    本文将探讨无线接入点(AP)和BSSID(MAC地址AP).我们不借助文件系统加密和文件系统中(仅内存中)的硬编码Payload即可获得后门Payload,通过该方法可绕过所有的杀软,可以不使用Pay ...

  4. [HTML5] Show Different Variations of Images Depending on the Viewport Width using Art Direction

    For small viewports, we may want to show a variation of the desktop image. A very common use case of ...

  5. svn 创建分支、切换分支 及 合并分支 操作

    关联远程仓库: 右键  ---  点击 ' SVN Checkout...' 生成 打开trunk目录,在trunk目录下新建两个文本文件A.java,B.java: 打开A.java输入以下内容: ...

  6. U盘 文件被隐藏解决办法

    原地址:http://www.deyi.com/thread-351635-1-1.html 方法:运行cmd( 在任意目录都行)单个文件 :attrib c:\"要修改的文件夹名字&quo ...

  7. XML语法笔记

    XML(可扩展标记语言) XML的特点: XML是一种标记语言,适合跨平台.跨语种信息交互XML被用于存储.传输数据XML可扩展性良好,没有预定义标签,需要用户自定义标签XML具有自我描述性XML采用 ...

  8. 使网页适应UIWebView的宽度

    比較简单的做法是:在- (void)webViewDidFinishLoad:这种方法中,改动JavaScript的值: //UIWebViewDelegate - (void)webViewDidF ...

  9. layer弹层

    获得 layer 文件包后,解压并将 layer 整个文件夹(不要拆分结构) 存放到你项目的任意目录,使用时,只需引入 layer.js 即可. 注意:引入layer.js前必须先引入jquery1. ...

  10. Arcgis Engine(ae)接口详解(3):featureClass的feature编辑和删除

    //由于测试数据不完善,featureClass在此要只设null值,真实功能要设实际的值 IFeatureClass featureClass = null; //获取某个字段的索引,后面取字段值用 ...