YII2 URL美化以及隐藏入口文件index.php

  1. 在web文件夹下,新建.htacess文件,文件内容写入
    # 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

  2. 在配置文件main.php中加入如下配置
    //url美化管理
            'urlManager' => [
                //是否美化url
                'enablePrettyUrl' => true,
                //是否隐藏入口文件index.php
                'showScriptName' => false,
                //url后缀
                'suffix' => '.shtml',
                'rules' => [
                ],
            ],

你可能感兴趣的:(yii)