You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

登录后无法通过Router重定向至主页面问题求助

Why Your Redirect Isn't Working

Got it, let's break down why your current setup isn't working and fix it right away:

  1. Your header() call is missing the required Location: prefix — the server won't recognize it as a redirect instruction without this.
  2. The relative path /../../../public/index.php doesn't align with your URL structure. Chances are your web server uses the public folder as the document root, so public/ doesn't show up in the actual browser URL. That path would try to point to a non-existent location outside your subdomain's root.

Fixes to Get You Redirected

Here are two straightforward, reliable solutions:

1. Root-Relative Path (Simplest Option)

Since your target is the root of sub.mydomain.de, just redirect directly to / — this will automatically map to your public/index.php file (assuming your server is configured correctly):

// After your login validation passes
if ($login_success) {
    // Enable output buffering if you're worried about accidental prior output
    ob_start();
    header("Location: /");
    exit(); // Always exit after redirect to stop further script execution
}

2. Absolute URL (Most Reliable Option)

If you want to eliminate any path ambiguity, use the full absolute URL of your main page:

if ($login_success) {
    ob_start();
    header("Location: https://sub.mydomain.de/");
    exit();
}

Key Reminders

  • No Output Before header(): Even a single space, newline, or HTML tag before your <?php tag will break the redirect. If you can't avoid accidental output, add ob_start(); at the very top of login.php to enable output buffering.
  • Exit After Redirect: Always call exit() or die() right after the header() call. This stops the rest of your script from running, preventing unexpected behavior or partial page renders.

内容的提问来源于stack exchange,提问作者F.Ghost

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:17:36