如何解决PHP路由器和nginx配置
我做了一个没有框架的php网站,我用了https://grafikart.fr/tutoriels/router-628的路由器! 使用 Apache 和 .htaccess 一切正常++,但不幸的是我必须使用 nginx !
我的 index.php 是:
<?php
if ($_COOKIE['lang'] == 'fr')
include './src/lang/fr.php';
else
include './src/lang/en.php';
require './vendor/autoload.php';
$router = new App\Router\Router($_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();
当路由被调用时,我的控制器看起来像这样:
<?php
namespace App\Controller;
class HomeController
{
public function show()
{
include './src/views/home/index.php';
}
}
对于我的 nginx 配置,我必须将所有 URL 重定向到我的 index.php ! 我发现:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
或:
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>;
}
但是我所有的研究都失败了:(
有人对我必须为我的路由器工作做的配置有任何想法
谢谢:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。