Silex路由问题(除了root给出404之外的其他路径)

时间:2012-11-16 20:25:44

标签: php silex

这似乎应该有效,但我收到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错误。

这里发生了什么?

1 个答案:

答案 0 :(得分:9)

网址是web/index.php之后的部分。因此/aboutweb/index.php/about匹配。

现在您要从网址中删除index.php位。您可以使用HTACCESS执行此操作,阅读this question以了解操作方法。