I have made a php website without framework and I've used the router of https://grafikart.fr/tutoriels/router-628 !
With Apache and a .htaccess all is ok++ but unfortunately I have to use nginx !
My index.php is:
<?php
if ($_COOKIE['lang'] == 'fr')
include './src/lang/fr.php';
else
include './src/lang/en.php';
require './vendor/autoload.php';
$router = new AppRouterRouter($_GET['url']);
include './src/views/layouts/header.php';
$router->get('/', "Home#show");
$router->get('/mention', "Mention#show");
$router->get('/office/:id', "Offices#show");
$router->get('/meeting/:id', "Meetings#show");
$router->post('/contact', "Contact#send");
include './src/views/layouts/footer.php';
$router->run();
And when a route is call, my controller look like this:
<?php
namespace AppController;
class HomeController
{
public function show()
{
include './src/views/home/index.php';
}
}
For my nginx config, I have to redirect all URL to my index.php !
I found :
location / {
try_files $uri $uri/ /index.php?$query_string;
}
or:
location / {
try_files $uri $uri/ /index.php?$args; #if doesn't exist, send it to index.php
}
location ~ .php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:<PORT>;
}
But all my research failed :(
Someone have any idea to witch config I have to do for my router work
Thank :)
question from:
https://stackoverflow.com/questions/65935152/php-router-and-nginx-configuration 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…