yii2.0的urlManager里面的rules定义路径入口路径使得其他路径失效问题?

'urlManager' => [

        'enablePrettyUrl' => true,//将r参数中的变掉
        'showScriptName' => false,//隐藏index.php
        'rules' => ["/" => "/default/index"],
    ],
    

观看了慕课网某视频,视频处理入口文件这么写的.但是,我直接用
http://www.yiibook.com/user/i...

这种格式就报错 The requested URL /user/index was not found on this server.还是必须用http://www.yiibook.com/index....这种格式,并且页面就一直在/default/index这个页面了,写别的地址也不管用了.查了很多资料.也没解决.这么写是不是不对呢?

阅读 3.5k
1 个回答

除了改Yii 2.0的config文件之外,还必须设置Apache的.htaccess文件,否则是不起作用的。

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

这个文件的位置应该放在web目录下。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题