gpt4 book ai didi

php - Silex 路由问题(除 root 之外的其他路径提供 404)

转载 作者:可可西里 更新时间:2023-11-01 00:09:57 24 4
gpt4 key购买 nike

这看起来应该可行,但我收到 404 错误。

我的应用看起来像这样:

lib/init.php:

$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());

和 web/index.php:

require_once __DIR__.'/../lib/init.php';

$app->get('/about', function() use ($app) {
return $app['twig']->render('about.twig.html');
})
->bind('about');

$app->get('/', function() use ($app) {
return $app['twig']->render('index.twig.html');
})
->bind('homepage');

$app->run();

我正在使用 MAMP 在我的本地机器上进行测试。当我访问 localhost:8888/web 时,它可以很好地呈现索引页面,没有问题,但是访问 localhost:8888/web/about 会出现 404 错误。

这是怎么回事?

最佳答案

url是web/index.php之后的部分。所以 /about 匹配 web/index.php/about

现在您要从 url 中删除 index.php 位。您可以使用 HTACCESS 执行此操作,请阅读 this question了解如何。

关于php - Silex 路由问题(除 root 之外的其他路径提供 404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13423910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com