1.首先保证开启apache的rewrite 模块
![]()
![]()
2.开启分布式配置文件AllowOverride All
3.在index.php同级目录下,创建 .htaccess 文件。写入一下内容
1
Options +FollowSymLinks
2
IndexIgnore */*
3
RewriteEngine on
4
5
# if a directory or a file exists, use it directly
6
RewriteCond %{REQUEST_FILENAME} !-f
7
RewriteCond %{REQUEST_FILENAME} !-d
8
9
# otherwise forward it to index.php
10
RewriteRule . index.php
4.在Yii2中配置:frontend/config/main.php中
1
'urlManager'=>[
2
'class' => 'yii\web\UrlManager', //指定实现类
3
'enablePrettyUrl' => true, // 开启URL美化
4
'showScriptName' => false, // 是否显示index.php
5
'suffix' => '.html', // 伪静态后缀
6
'rules'=>[
7
// 自定义路由规则
8
],
9
],
配置好后访问方式 http://yii.com/user/add.html