IIS only loading the base route /, regardless of URI

Hello,

I am running into an issue on only one of my servers where Slim 3 is only loading the / path regardless of the URL.

For example, I have the following app which is located in the /app/api/ folder on my web server.

require_once("Slim3/autoload.php");
$app = new \Slim\App([
    'settings' => [
        'displayErrorDetails' => true
    ]
]);

$app->get('/', function ($request, $response, $args) {
    return $response->write('Hello from /!');
});

$app->get('/test', function ($request, $response) {
    return $response->write('Hello from /test!');
});

$app->run();

When I load the app on most of my servers with https://example.com/app/api/test, I get the correct output of Hello from /test!. However on the server I am having the issue on, I receive a response of Hello from /!

We are using the IIS Rewrite 2.1 module which has the following configuration on all of the servers.

<rules>
    <rule name="Slim3 Rewrite" stopProcessing="true">
        <match url="(.*\/api\/)(.*)$" />
        <action type="Rewrite" url="{R:1}/index.php?q={R:2}" logRewrittenUrl="true" />
    </rule>
</rules>

This rewrites the URL as https://example.com/app/api/index.php?q=test. I can confirm from the IIS logs that all the servers are rewriting the URL correctly.

The only difference I can see is when I do a var dump on the request object. I get the following values for the uri object on the server with the issue:

[uri:protected] => Slim\Http\Uri Object
(
    [scheme:protected] => https
    [user:protected] =>
    [password:protected] =>
    [host:protected] => example.com
    [port:protected] => 443
    [basePath:protected] =>
    [path:protected] => /
    [query:protected] => q=test
    [fragment:protected] =>
)

This is what I see on the others server where is is working:

[uri:protected] => Slim\Http\Uri Object
(
    [scheme:protected] => https
    [user:protected] =>
    [password:protected] =>
    [host:protected] => example.com
    [port:protected] => 443
    [basePath:protected] => /app/api
    [path:protected] => test
    [query:protected] => q=test
    [fragment:protected] =>
)

I have reinstalled IIS, IIS Rewrite Module, PHP, and re-downloaded the Slim package. Anyone else experienced this issue or have suggestions on where to look next?

I use IIS for work to.

Slim 3 lives in folder foo. So does web.config.

I make requests to slim via
.com/foo/public/hello/world

in routes.php
app.get(’/hello/world’, function(){});

so everything is relative to the the folder it lives in. I don’t put slim in the root directory because that is where all the Microsoft stuff is happening. It’s easier to just have slim api’s live in a sub folder.

I do not have slim in the root directory, I have it in /app/api, the issue is that the Slim URI object is returning / when I am requesting /app/api/test

@chillheart have you solved this issue? I have the same situation.