2
这段代码来自heroku的一个例子。但除了路线/,我添加的任何东西都不起作用。它显示404:Heroku silex route show 404 except“/”
在此服务器上找不到请求的URL/e。
$app->match('/', function(Symfony\Component\HttpFoundation\Request $request) use ($app) {
return $app['twig']->render('index.twig');
});
$app->match("/dump", function(Symfony\Component\HttpFoundation\Request $request) use ($app) {
return new Response('Thank you for your feedback!', 201);
})->bind("dump");
$app->get("/t", function() use ($app) {
return new Response('Thank you for your feedback!', 201);
})->bind("t");
$app->get("/d", function() {
return new Response('Thank you for your feedback!', 201);
})->bind("d");
$app->get("/e", function() {
return new Response('Thank you for your feedback!', 201);
});
$app->run();
编辑1 我部署它直接Heroku的服务器上(Heroku的自动生成每个推到主分支)
编辑2 我的工作区:
bin\worker.php
www\index.php <== the snippet is from this file
www\list.php
apache_app.conf
app.php <== basic init, return Silex\Application $app
Procfile
apache_app.conf
的内容复制自this link。 RewriteEngine叙述在
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
我想,我需要以某种方式修改Apache的配置,但我不明白htaccess的语法。
是'/ index.php/e'的作品吗?你有没有配置你的网络服务器?你使用的是Apache还是nginx? – Federkun
@Federkun不,它没有用。由于我将它部署在heroku服务器上,我不认为我可以配置任何东西。据我所知,他们使用apache2。 – Ngoc
请参阅http://silex.sensiolabs.org/doc/2.0/web_servers.html#apache。 '/ index.php/e'(其中'/ index.php是你的前端控制器)应该可以工作。当你转到'/ index.php'时,它是否正确返回索引页? – Federkun