yii2.0 url美化-apache服务器

时间:2022-12-11 13:14:20

//配置内容

'urlManager' => [
  'enablePrettyUrl' => true,
  'enableStrictParsing' => false, //不启用严格解析
  'suffix' => '',
  'showScriptName' => false,
  'rules' => [
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
  ],
],

在根目录下,添加.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