首先配置下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',

最新文章

  1. Linux线程同步:条件变量
  2. 【转载】Delphi7从子线程中发送消息到主线程触发事件执行
  3. gulp系列:自动构建及刷新浏览器
  4. android音视频点/直播模块开发
  5. python如何安装pip和easy_installer工具
  6. DeviceOne开发HelloWord
  7. Android 快速开发框架网络篇-Android-Async-Http
  8. jsp注释方式
  9. HttpURLConnection和HttpClient
  10. solr 3.5 配置及server设置
  11. Extjs4.0.7 MVC Architecture异常
  12. 【NOIP2014】子矩阵
  13. SpringMVC第五篇【方法返回值、数据回显、idea下配置虚拟目录、文件上传】
  14. MyBatis学习总结——实现关联表查询(转)
  15. face detection[Face R-CNN]
  16. python 传递多个参数
  17. MyBatis学习之输入输出类型
  18. 对JSON数据的解析(数据推送接口)
  19. PCIe调试心得_DMA part2
  20. (oneway void) release中oneway的意思

热门文章

  1. Mac OS X 下安装python的MySQLdb模块
  2. KernelHacking
  3. GeoServer发布Heatmap
  4. 用 jQuery实现图片等比例缩放大小
  5. android CheckBox使用和状态获得
  6. 【kotlin】long转化为date类型 或者date字符串
  7. 使用Myeclipse + SVN + TaoCode 免费实现项目版本控制的详细教程
  8. Windows下Python安装pyecharts
  9. indexOf 和 lastIndexOf 的区别
  10. 关于Java中强制类型转换的问题