我必须关闭对我的index.php主页的访问,我用以下代码修改了siteController.php:
public function accessRules() {
return array(
// allow all users to perform 'index' and 'view' actions *
array('allow',
'actions' => array('index','view'),
'users' => array('admin'),
),
// allow authenticated user to perform 'create' and 'update' actions @
array('allow',
'actions' => array('create','update'),
'users' => array('admin'),
),
// allow admin user to perform 'admin' and 'delete' actions
array('allow',
'actions' => array('admin','delete'),
'users' => array('admin'),
),
// deny all users
array('deny',
'users' => array('*'),
),
);
}
因为我只允许管理员访问。在这些操作之后,我看到重定向正在工作,url变成了index.php/site/login,但我得到的不是login/pass表单ERR_TOO_MANY_REDIRECTS
。希望你能理解我)
我遇到了同样的问题,解决方案是将"error"操作添加到规则中,允许所有用户访问它。我之所以这么做,是因为在进行更新后,它生成了一个错误,并且无法访问错误操作。
我和config/main.php
中的urlManager
有相同的问题。我的urlManager配置是这样的:
'urlManager' => [
'baseUrl' => $baseUrl,
'class' => 'yii'web'UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => [
'<controller:'w+>/<id:'w+>' => '<controller>',
'<controller:'w+>/<action:'w+>/<id:'w+>' => '<controller>/<action>',
'<controller:'w+>/<action:'w+>' => '<controller>/<action>',
]
]
必须是
'<controller:'w+>/<id:'d+>' => '<controller>',
它与RegEx有关。这是文档
将login
操作添加到访问规则:
['allow',
'actions'=>['index','view','login'],
'users'=>['admin'],
],