I have set up a docker container with php + nginx. I made a change to the nginx config so that it redirects to index.php in the root folder if it does not find any file or directory. It started looping adding /index.php/ to the url infinitely. I changed the config back to:
server {
listen 0.0.0.0:80;
root /var/www/html;
location / {
index index.php index.html;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
And now it only redirects once, to localhost/index.php/.
I dont think its my poorly built php routers fault as when I remove that code it continues to redirect.
Here is the routers code from index.php anyway:
<?php
$reqParsed = parse_url($SERVER['REQUESTURI']);
$viewsDir = '/static/views/';
$manifest = jsondecode(fileget_contents(__DIR . '/v1/manifest.json'), true);
switch ($reqParsed['path']) {
case '':
case '/':
require __DIR . $viewsDir . 'home.php';
break;
case '/posts/':
if (isset($_GET['id'])) {
if (isset($manifest['posts'][$GET['id']])) {
require DIR . $viewsDir . 'posts/post-view.php';
}else {
require DIR . $viewsDir . 'posts/post-404.php';
}
}else{
require _DIR . $viewsDir . 'posts/posts.php';
}
echo $GET['id'];
break;
default:
httpresponse_code(404);
require __DIR . $viewsDir . '404.php';
}
?>
Thanks for any help in advance!