Yii2 url地址美化与重写

main.php中’components'=>[] 中添加如下代码:

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,//隐藏index.php
//            'enableStrictParsing' => false,
            'suffix' => '.html',//后缀,如果设置了此项,那么浏览器地址栏就必须带上.html后缀,否则会报404错误
            'rules' => [
            ],
        ],

添加.htaccess文件:

Options +FollowSymLinks
    IndexIgnore */*
    RewriteEngine on
 
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
 
    # otherwise forward it to index.php
    RewriteRule . index.php

 

posted @ 2018-02-08 12:17  不一样的开始  阅读(161)  评论(0编辑  收藏  举报