后台登录后跳转问题

bug问题 · cfop · 于 4年前 发布 · 1000 次阅读

版本2.4.9 因项目需要,网站需署在子目录,后台登录会跳转到根网站地址 比如我后台部署在 test.com/test/ 登录后跳转到了 test.com 检查后发现 \vendor\fancyecommerce\fecshop\app\appadmin\modules\Fecadmin\controllers\LoginController.php 39行、51行的Yii::$app->getResponse()->redirect("/")->send();有问题 改为Yii::$app->getResponse()->redirect(['/'])->send();就可以正常跳转了。 不知道这算不算一个bug,在此提出。

共收到 5 条回复
Fecmall#14年前 0 个赞

Yii::$app->getResponse()->redirect("/")->send(); 正常部署是没有问题的,登陆后可以跳转的。@

@yii/web/Response.php该函数redirect代码:

public function redirect($url, $statusCode = 302, $checkAjax = true)
    {
        if (is_array($url) && isset($url[0])) {
            // ensure the route is absolute
            $url[0] = '/' . ltrim($url[0], '/');
        }
        $url = Url::to($url);
        if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) {
            $url = Yii::$app->getRequest()->getHostInfo() . $url;
        }

        if ($checkAjax) {
            if (Yii::$app->getRequest()->getIsAjax()) {
                if (Yii::$app->getRequest()->getHeaders()->get('X-Ie-Redirect-Compatibility') !== null && $statusCode === 302) {
                    // Ajax 302 redirect in IE does not work. Change status code to 200. See https://github.com/yiisoft/yii2/issues/9670
                    $statusCode = 200;
                }
                if (Yii::$app->getRequest()->getIsPjax()) {
                    $this->getHeaders()->set('X-Pjax-Url', $url);
                } else {
                    $this->getHeaders()->set('X-Redirect', $url);
                }
            } else {
                $this->getHeaders()->set('Location', $url);
            }
        } else {
            $this->getHeaders()->set('Location', $url);
        }

        $this->setStatusCode($statusCode);

        return $this;
    }

cfop#24年前 0 个赞

@Fecmall #1楼 正常部署是没问题的,我这个主要是部署在了子目录。改为Yii::$app->getResponse()->redirect(['/'])->send();是可以兼容子目录的,希望在下一个版本修复一下。暂时用controllerMap重写解决了。

Fecmall#34年前 0 个赞

子目录,可以在@app/web/下加个一个子目录解决,类似于多语言的解决方案:http://fecshop.appfront.fancyecommerce.com/cn/

@appfront/web/cn

这个不是bug,不予解决,不是在fecmall的规则范围内。

cfop#44年前 0 个赞

@Fecmall [#3楼](#comment3) 你这个是前台吧,我现在说的是后台,后台怎么配置后台的子目录啊?

Fecmall#54年前 0 个赞

@cfop #4楼 fecmall没这个设计,想要这样做,自行解决

为什么要子目录?搞个子域名就完事。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics