Php Yii 2-如果已登录,如何重定向到根目录中的某个前端页面;如果在根目录中是来宾,如何重定向到前端登录页面?
我有个问题。我尝试在根文件夹中使用.htaccess重定向,如下所示: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
- 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重定向?我认为这是从根目录重定向到页面的唯一方法是否需要在项目的根文件夹中创建此控制器?否。请参见此处: