1

我想在yii2中使用漂亮的 url

在 web 目录.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',
     ],
 ],

当 url 是像 urlmanager 一样的localhost页面加载 但在or或任何其他要加载的 url 上时,它会再次加载。view/indexlocalhost/aboutlocalhost/about.phpview/aboutview/index

4

2 回答 2

0

改变

'urlManager' => [
        'class'=>'yii\web\UrlManager', 
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        //'enableStrictParsing' => false,
        'rules' => [
        //.....
        ],
    ],
于 2018-05-22T06:11:27.263 回答
0

也许你应该改变

enablePrettyUrl=>false

enablePrettyUrl=>true

于 2015-09-24T16:26:19.890 回答