这似乎应该有效,但我收到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错误。
这里发生了什么?
答案 0 :(得分:9)
网址是web/index.php
之后的部分。因此/about
与web/index.php/about
匹配。
现在您要从网址中删除index.php
位。您可以使用HTACCESS执行此操作,阅读this question以了解操作方法。