2012-11-16 54 views
3

這似乎應該工作,但我得到一個404錯誤。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來測試我的地方機。當我訪問本地主機:8888 /網絡它呈現索引頁面沒有問題,但訪問本地主機:8888 /網絡/約出現404錯誤。

這是怎麼回事?

回答

9

該網址是web/index.php之後的部分。所以​​匹配web/index.php/about

現在你想從url中刪除index.php位。你可以用HTACCESS來做到這一點,閱讀this question瞭解如何。

+0

謝謝!我認爲這與'.htaccess'有關,但是自從我編寫任何PHP之後已經很久了。 – camdub