I'm using Yii 1.1.17, and i noticed on some of my pages where i want just registered users to be able to view I'm getting a soft 404 error on Google's webmasters tools.
For example
http://www.example.com/sell/
when you go to http://www.example.com/sell/view
it would redirect you to http://www.example.com/login
Right now i only have 240 soft 404 errors. The view action was not set to registered users only at first.But after a couple of months after launching my site. I changed it. Then the errors starting poping up.
Is there a way to fix this? or a work around?
here is accessRules for the view
action that is only for registered users:
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index', 'new'),
'users'=>array('*'),
),
array('allow',
'actions'=>array('view'),
'users'=>array('@'),
),
array('allow',
'actions'=>array('admin','delete', 'update', 'create','update','upload'),
'expression'=>'app()->user->isAdmin()',
),
array('deny',
'users'=>array('*'),
),
);
}
You could add a deniedCallback
as
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index', 'new'),
'users'=>array('*'),
'deniedCallback' => array($this, 'redirectToLogin'),
),
array('allow',
'actions'=>array('view'),
'users'=>array('@'),
'deniedCallback' => array($this, 'redirectToLogin'),
),
array('allow',
'actions'=>array('admin','delete', 'update', 'create','update','upload'),
'expression'=>'app()->user->isAdmin()',
'deniedCallback' => array($this, 'redirectToLogin'),
),
array('deny',
'users'=>array('*'),
'deniedCallback' => array($this, 'redirectToLogin'),
),
);
}
public function redirectToLogin($user = null, $rule = null){
Yii::app()->controller->redirect('/login', true, 403);
}
You can then redirect with whatever status code you'd like.
You can find out more about deniedCallback
here.
Find out more about redirect
here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With