JSOPanel Get started
Help Center › Administrators › An application keeps redirecting back to its own login or setup page

An application keeps redirecting back to its own login or setup page

Diagnosing a redirect loop caused by an application with more than one entry point, with the exact fix to apply.

Most PHP applications have a single entry point, usually one index.php that every request is sent through. Some older or more modular applications don't work that way: they have several independent sections, each with its own entry point in its own folder, for example a sign-in section, an admin section, and a reporting section. A visitor's browser shows this as ERR_TOO_MANY_REDIRECTS ("this page isn't working: redirected you too many times") the moment it reaches one of those sections, most often the sign-in page itself.

Why this happens

A domain's web server rule normally falls back to the application's one main entry file whenever the requested address doesn't match a real file on disk, which is exactly right for a single-entry-point application. For an application with several independent sections, that same fallback sends a request for one section's own address to the main entry file instead - and the main entry file, seeing a visitor who isn't signed in yet, sends them straight back to the sign-in address. Since that address still isn't a real file either, the same thing happens again, forever.

Nothing is actually broken in the application itself. Every piece involved - the sign-in page, the account, the application's own files - is working correctly on its own. The one thing missing is a web server rule telling it that this application has more than one entry point.

How to confirm this is what's happening

  1. Check the account's own error log for the domain at the moment of the redirect. If nothing fatal is being logged - no PHP error, nothing - that's consistent with this: the application isn't crashing, it's correctly doing what its code says to do, just being asked to do it from the wrong starting point.
  2. Look at which address keeps repeating in the browser's address bar. If it's the application's own sign-in or setup address, and the application genuinely does have separate sections living in their own subfolders (check whether each one has its own index.php inside it), this is the cause.

The fix

Go to Service Configuration → nginx, select the affected domain from the list, and paste this into its custom rules box, then save. It's checked against the live server before being applied - if it would stop nginx from starting, it's refused and nothing changes.

Replace admin, api, and session with whatever top-level folders in the application actually contain their own index.php - check the application's own files, don't guess:

location ~ ^/(admin|api|session)(?!.*\.php)(/|$) {
    try_files $uri $uri/ /$1/index.php?$query_string;
}

Reload the application's sign-in page afterward; it should load normally instead of redirecting back to itself.

Tip: the (?!.*\.php) part matters more than it looks. Without it, this same rule also matches the very file it rewrites the request to, so the request gets handed to this rule a second time, finds a real file sitting there, and serves it as a plain download instead of letting it run as PHP. Leaving this part out is the single most common mistake when writing a rule like this one - see the custom nginx rules reference article in this section for the full explanation.

If the loop is still there afterward

A small number of applications have their own, separate check that sends an unsigned-in visitor to the sign-in page - and if that check doesn't know to leave the sign-in page itself alone, the application will send a visitor straight back to it even once the rule above is correctly routing requests. This shows up as the exact same symptom, so it's easy to mistake for the rule not having worked.

  1. Open File Manager, find the file responsible for signing visitors in or out (often named something like Auth, AuthMiddleware, or similar, usually not far from the sign-in page's own files), and open it for editing.
  2. Before changing anything, download a copy of the file so the original is easy to restore.
  3. Find the check that decides whether a visitor is signed in, near the top of the function that runs on every request. Add an exemption for the sign-in address itself, before that check runs, along these lines:
    if (str_starts_with($request->getUri()->getPath(), "/session")) {
        return $handler->handle($request);
    }
    The exact wording varies by application - the idea is the same regardless: the sign-in page (and anything else a signed-out visitor genuinely needs, such as a password reset page) has to be reachable without already being signed in, or nobody can ever reach it to sign in at all.
  4. Save the file and reload the sign-in page again.
Tip: this second fix is specific to how an individual application checks who's signed in, so it looks different in every application. If you're not confident editing it, the nginx rule above resolves the large majority of cases on its own - this step is only needed the rare times it doesn't.