Enable clean URL in Yii2

后端 未结 11 1195
攒了一身酷
攒了一身酷 2020-11-27 12:36

How can I enable clean urls in Yii2. I want to remove index.php and \'?\' from url parameters. Which section needs to be edited in Yii2 for that?

11条回答
  •  不知归路
    2020-11-27 12:44

    Step1: in project config/main.php eg: frontend/config/main.php

    'urlManager' => [
                'enablePrettyUrl' => true,
                'showScriptName' => false,
                'rules' => [],
            ]
    

    Step2: create .htaccess file inset web folder eg: frontend/web

    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
    
    #php_flag  display_errors        on
    #php_value error_reporting       2039
    

提交回复
热议问题