Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Nginx Redirecting from Localhost to localhost/index.php/. (Nginx + Php)

$
0
0

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 http://localhost/index.php/.

I don't 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!


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>