yii2设置伪静态
来源:互联网 发布:中和支付网络pos机 编辑:程序博客网 时间:2024/06/06 06:51
Apache服务器的配置
修改httpd.conf配置文件
- 将LoadModule rewrite_module modules/mod_rewrite.so前面的注释#号去掉。
- 添加如下内容
<Directory "path/to/basic/web"> # use mod_rewrite for pretty URL support RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php # ...other settings...</Directory>
注意其中的path/to/basic/web修改成你的根目录,最后不要忘记重启apache服务器。
Nginx服务器的配置
修改nginx.conf配置文件,在域名对应的server{}内添加如下内容
location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args;}
最后不要忘记重载配置文件。
yii2代码的配置
修改config/web.php,在components数组中添加如下内容(去掉前后的注释)
'components' => [ ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], ...],
这时再刷新网页,就能看到连接的形式发生了改变。此时默认会将/index.php?r=controller/action
这样的形式修改为/controller/action
(如果含有参数,则将/index.php?r=controller/action&...
改为/controller/action?...
)。
为了更好的将链接个性化配置,可以参照如下例子,在rules这个空的数组中添加相应的内容。
- 文章列表
/index.php?r=post/index
添加'post'=>'post/index'
- 通过id查看文章
/index.php?r=post/view&id=123
添加'post/<id:\d+>'=>'post/view'
其中\d+等价于[0-9]+
- 通过标题查看文章
/index.php?r=post/view&title=hello-world
添加'post/<title:\w+>'=>'post/view'
其中\w+等价于[A-Za-z0-9_]+
最后config/web.php可能如下所示
'components' => [ ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'post'=>'post/index', 'post/<id:\d+>'=>'post/view', ], ], ...],
参考:
- configuring-web-servers
0 0
- yii2设置伪静态
- YII2伪静态(路由配置)
- Yii2中nginx的伪静态
- DZ伪静态设置
- apache伪静态设置
- iis 伪静态设置
- php设置伪静态
- php伪静态设置
- ISS伪静态设置
- 伪静态的设置
- MVC4 伪静态设置
- Apache 伪静态设置
- 如何设置伪静态
- apache 伪静态设置
- mvc4设置伪静态---路由伪静态
- discuz论坛伪静态设置
- iis6 .net伪静态设置
- iis 中的伪静态设置
- C经典 内存分配解析
- Java学习笔记之输入输出流(一) File、文件字节流、文件字符流
- web学习笔记-httpServletResponse一
- C++的强制类型转换
- 设计模式笔记---简单工厂
- yii2设置伪静态
- java 多线程
- 基于高斯方法的图像模糊
- linux下使用GDB调试程序
- 三菱FX3UPLC项目总结
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- 翻车后的NOIP。。。
- hdu2072——单词数(STL,set)
- 51nod 1066 Bash游戏