yii2的url重写方法

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值