URLManager with a rule to another application.

Hey guys.

Using URLManager is possibly create a rule that redirect the user to another application ( like backend ) ?

Something like this:





    'components' => [

        'urlManager' => [

            'rules' => [

                '' => 'backend/site/default/index',






i think you must put a slash at the first like so


    'components' => [

        'urlManager' => [

            'rules' => [

                '' => '/backend/site/default/index',

or try to add a full link

try it & let me know the result ;)

In this way you are not making redirect, you are simply matching empty request to specific action.

If you need really a redirect, you should handle empty request to an action and then make redirect, as:




    'components' => [

        'urlManager' => [

            'rules' => [

                '' => 'default/index',



In DefaultController:




public function actionIndex() {

     return $this->redirect('backend/site/default/index');

}



I think that this is the simplest solution to do it.

That is already my solucion. But with that we loose session variables, like this:

  1. Yii::$app->session->setFlash(‘danger’, Module::t(‘users’, ‘BACKEND_FLASH_FAIL_ADMIN_CREATE’));

  2. Refresh the application;

  3. Goes do frontend; ( that have a redirect to backend ).

  4. Goes to backend ( via redirect, session variables are lost because of the redirect );

I already tried that, but the URLManager class don’t support that :)