在yii2中创建漂亮的URL无法正常工作

时间:2015-09-24 15:22:59

标签: yii2 pretty-urls

我想在 yii2

中使用漂亮网址

在网络目录 .htaccess 文件中:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

config / web.php

'urlManager' => [
     'class' => 'yii\web\UrlManager',
     'baseUrl' => '/',
     'enablePrettyUrl' => false,
     'showScriptName' => false,
     'enableStrictParsing' => true,
     'rules' => [
         '/' => 'view/index',
         'about' => 'view/about',
         'contact' => 'site/contact',
         'login' => 'site/login',
         'logout' => 'site/logout',
         'captcha' => 'site/captcha',
         'signup' => 'site/signup',
     ],
 ],

当网址为localhost时,网页加载view/index就像urlmanager一样 但是在localhost/aboutlocalhost/about.php或任何其他要加载view/about的网址上,它会再次加载view/index

2 个答案:

答案 0 :(得分:0)

也许你应该从

改变

enablePrettyUrl=>false

enablePrettyUrl=>true

答案 1 :(得分:0)

改变
'urlManager' => [
        'class'=>'yii\web\UrlManager', 
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        //'enableStrictParsing' => false,
        'rules' => [
        //.....
        ],
    ],