Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii 2-如果已登录,如何重定向到根目录中的某个前端页面;如果在根目录中是来宾,如何重定向到前端登录页面?_Php_Apache_.htaccess_Redirect_Yii2 - Fatal编程技术网

Php Yii 2-如果已登录,如何重定向到根目录中的某个前端页面;如果在根目录中是来宾,如何重定向到前端登录页面?

Php Yii 2-如果已登录,如何重定向到根目录中的某个前端页面;如果在根目录中是来宾,如何重定向到前端登录页面?,php,apache,.htaccess,redirect,yii2,Php,Apache,.htaccess,Redirect,Yii2,我有个问题。我尝试在根文件夹中使用.htaccess重定向,如下所示: localhost/planificacion\u talleres/如果用户已登录,则重定向到localhost/planificacion\u talleres/frontend/web/index.php?r=planificacion localhost/planificacion\u talleres/如果用户是来宾,则重定向到localhost/planificacion\u talleres/frontend

我有个问题。我尝试在根文件夹中使用.htaccess重定向,如下所示:

  • localhost/planificacion\u talleres/如果用户已登录,则重定向到localhost/planificacion\u talleres/frontend/web/index.php?r=planificacion
  • localhost/planificacion\u talleres/如果用户是来宾,则重定向到localhost/planificacion\u talleres/frontend/web/index.php?r=site

但我不知道如何使用相同的.htaccess重定向到使用条件的其他页面。我需要帮助,请

我认为使用
.htaccess
重定向是个坏主意,因为在这种情况下,您无法根据其他条件管理这些重定向

我建议使用应用程序重定向,例如:

class DefaultController extends \yii\web\Controller
{

    public function actionIndex()
    {
        $targetRoute = \Yii::$app->user->isGuest
            ? ['site']
            : ['planificacion'];

        return $this->redirect($targetRoute);
    }

}

是否需要使用.htaccess重定向?我认为这是从根目录重定向到页面的唯一方法是否需要在项目的根文件夹中创建此控制器?否。请参见此处: