我想在 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/about
或localhost/about.php
或任何其他要加载view/about
的网址上,它会再次加载view/index
。
答案 0 :(得分:0)
也许你应该从
改变 enablePrettyUrl=>false
到
enablePrettyUrl=>true
答案 1 :(得分:0)
随
改变'urlManager' => [
'class'=>'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
//'enableStrictParsing' => false,
'rules' => [
//.....
],
],