dsft8327 2017-02-24 03:01
浏览 36

Yii 2 - 如果记录,如何重定向到root中的某个前端页面,如果是root用户,则重定向到前端登录页面?

I have a problem. I tried to use an .htaccess in the root folder to redirect like this:

  • localhost/planificacion_talleres/ redirect to localhost/planificacion_talleres/frontend/web/index.php?r=planificacion if User is logged
  • localhost/planificacion_talleres/ redirect to localhost/planificacion_talleres/frontend/web/index.php?r=site If User is guest.

But I don't know how to redirect using the same .htaccess to other pages using a condition. I need help, please

  • 写回答

1条回答 默认 最新

  • dongzhi4498 2017-02-24 12:58
    关注

    I think it is bad idea to redirect using .htaccess, because in this case you can't manage these redirects depending on other conditions.

    I recommend to use application redirects, for instance:

    class DefaultController extends \yii\web\Controller
    {
    
        public function actionIndex()
        {
            $targetRoute = \Yii::$app->user->isGuest
                ? ['site']
                : ['planificacion'];
    
            return $this->redirect($targetRoute);
        }
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办