Seen an old post with the same problem as I have (link below) and it did not have any solution:
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, $…
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?
odan
December 12, 2022, 9:46pm
2
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.