title: Wrong Redirection CakePHP
body: <h1>Redirect AuthComponent::$unauthorizedRedirect</h1>
  
  <p>when a user accesses an action where it is not permitted to access the _unauthorized method redirects incorrectly</p>
  
  <p>correct: localhost / project / index</p>
  
  <p>where he's redirecting: localhost / project / project / index</p>
  
  <p>I am using acl</p>
  
  <p><strong>AppController.php</strong></p>
  
  <pre><code>&lt;?php
  App::uses('Controller', 'Controller');
  class AppController extends Controller {
  
  public $components = array('Acl','Session','DebugKit.Toolbar','RequestHandler','Auth');
  public $helpers = array('Html','Form','Session');
  public $uses = array('Role');
  public $roleId;
  public $UAP;
  public $aroId;
  
  public function beforeFilter()
  {
      if ($this-&gt;Session-&gt;check('Config.language')) {
          Configure::write('Config.language', $this-&gt;Session-&gt;read('Config.language'));
      }
      $this-&gt;Auth-&gt;authorize = array(
          AuthComponent::ALL =&gt; array('actionPath' =&gt; 'controllers/','userModel' =&gt; 'Role'),
          'Actions',
          );
      $this-&gt;Auth-&gt;authenticate = array(
          'Blowfish' =&gt; array(
              'userModel' =&gt; 'User'
              )
          );
      if(!$this-&gt;_isAdmin()){
          $this-&gt;roleId = $this-&gt;getRoleId();
          $this-&gt;UAP = $this-&gt;Role-&gt;find('first',array('conditions'=&gt;array('Role.id'=&gt;$this-&gt;roleId)));
          $aro = $this-&gt;Acl-&gt;Aro-&gt;find('first',array(
              'conditions'=&gt;array(
                  'Aro.model'=&gt;'Role',
                  'Aro.foreign_key'=&gt;$this-&gt;roleId)));
          $this-&gt;aroId = $aro['Aro']['id'];
          $allow = array_merge($this-&gt;_getAllowed(), array('display'));
          $this-&gt;Auth-&gt;allowedActions = $allow;
      }
      //Configure AuthComponent
      $this-&gt;Auth-&gt;loginAction = array(
          'controller' =&gt; 'users',
          'action' =&gt; 'login'
          );
      $this-&gt;Auth-&gt;logoutRedirect = array(
          'controller' =&gt; 'users',
          'action' =&gt; 'login'
          );
      $this-&gt;Auth-&gt;loginRedirect = array(
          'controller' =&gt; 'pages',
          'action' =&gt; 'display',
          'home'
          );
      $this-&gt;Auth-&gt;authError = __('Not Authorized');
      return parent::beforeFilter();
  }
  
  protected function _getAllowed($actionsIds = null, $controllerActions = null){
      if(is_null($actionsIds)){
          $actionsIds = $this-&gt;_getAllowedActionsIds();
      }
      if(is_null($controllerActions)){
          $controllerActions = $this-&gt;_getControllerActions();
      }
      $allow = array();
      foreach ($actionsIds as $value) {
          array_push($allow, $controllerActions[$value]);
      }
      return $allow;
  }
  
  protected function _getAllowedActionsIds($allowedActions = null){
      if(is_null($allowedActions)){
          $allowedActions = $this-&gt;_getAllowedActions();
      }
      return array_values($allowedActions);
  }
  
  protected function _getAllowedActions($aroId = null, $acoId = null){
      if(is_null($aroId)){
          $aroId = $this-&gt;aroId;
      }
      if(is_null($acoId)){
          $acoId = $this-&gt;_getControllerActionsIds();
      }
      $result = $this-&gt;Acl-&gt;Aco-&gt;Permission-&gt;find('list',array(
          'conditions'=&gt;array(
              'Permission.aro_id'=&gt;$aroId,
              'Permission.aco_id'=&gt;$acoId,
              'Permission._create'=&gt;1,
              'Permission._read'=&gt;1,
              'Permission._update'=&gt;1,
              'Permission._delete'=&gt;1,
              ),
          'fields'=&gt;array('id','aco_id'),
          'recursive'=&gt;'-1'));
      return $result;
  }
  
  protected function _getControllerActionsIds($controllerActions = null){
      if(is_null($controllerActions)){
          $controllerActions = $this-&gt;_getControllerActions();
      }
      return array_keys($controllerActions);
  }
  
  protected function _getControllerActions($node = null){
      if(is_null($node)){
          $node = $this-&gt;_getNodeController();
      }
      return $this-&gt;Acl-&gt;Aco-&gt;find(
          'list',array(
              'conditions'=&gt;array('Aco.parent_id'=&gt;$node['0']['Aco']['id']),
              'fields'=&gt;array('Aco.id','Aco.alias'),
              'recursive'=&gt;'-1',
              ));
  }
  
  protected function _getNodeController(){
      return $this-&gt;Acl-&gt;Aco-&gt;node("controllers/{$this-&gt;name}");  
  }
  
  protected function _isAdmin(){
      if($this-&gt;Auth-&gt;user() &amp;&amp; $this-&gt;Auth-&gt;user('role_id') == 1){
          $this-&gt;Auth-&gt;allow();
          return true;
      }
      return false;
  }
  
  public function getRoleId(){
      if(!is_null($this-&gt;Auth-&gt;user('role_id'))){
          return $this-&gt;Auth-&gt;user('role_id');
      }
      return 9; //Usuário não cadastrado
  }
  }
  ?&gt;
  </code></pre>