IIS only loading the base route /, (Slim 3 + IIS)

Seen an old post with the same problem as I have (link below) and it did not have any solution:

So, here I am with the same problem. I use slim 3.12.4 and IIS on a Windows 10 development PC.

No matter what route I put in the URI it only loads the base one.

Any thoughts?

We have figured out a solution for Slim 3. See here:

If you run Slim in a subdirectory you may also have to fix the basePath:

$container['environment'] = function () {
    $scriptName = $_SERVER['SCRIPT_NAME'];
    $_SERVER['SCRIPT_NAME'] = dirname(dirname($scriptName)) . '/' . basename($scriptName);

    return new \Slim\Http\Environment($_SERVER);
};

This working example assumes that you store your front-controller file (index.php) under: {project-root}/public/index.php

Hi!

Your reply took me to an interesting fact: my PHP running under IIS does not have the $_SERVER['REQUEST_URI'] variable.

After many googlings I still haven’t find an anser to “why my IIS does not have REQUEST_URI variable while other IIS server have?”

I added this function at the beginning of the code and that did the trick:

if (!isset($_SERVER['REQUEST_URI'])) {
  if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
  } else {
    $_SERVER['REQUEST_URI'] = "/";
  }
}

Does anyone have the answer to the REQUEST_URI variable missing in some IIS servers?

Solved! For some unknown reason the PHP was set up as CGI Module on IIS instead of Fast CGI Module. After that was adjusted everything worked as intended.