Enable clean URL in Yii2

后端 未结 11 1199
攒了一身酷
攒了一身酷 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:58

    Just to add to this discussion - I've just installed Yii2, and it includes the following commented-out code in config/web.php:

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

    If you add the .htaccess file in the accepted answer, then just uncomment the above, pretty URLs will work (I have no idea what the "rules" in the accepted answer are for, but everything seems to work without them).

提交回复
热议问题