未找到Silex路由

use*_*896 6 php url-routing silex

我第一次使用Silex.在本地开发的同时一切正常.一旦将所有内容上传到生产服务器,参数化路由就不再起作用了.

你有什么主意吗?
我错过了某处的生产配置吗?
我在哪里丢失了文件权限?

我有两个例外:

NotFoundHttpException: No route found for "GET /prevendita/hello/sadfasdf"
in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 92
  at RouterListener->onKernelRequest(object(GetResponseEvent))
  at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 164
  at EventDispatcher->doDispatch(array(array(object(Application), 'onEarlyKernelRequest'), array(object(SessionServiceProvider), 'onEarlyKernelRequest'), array(object(RouterListener), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(Application), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 53
  at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 110
  at HttpKernel->handleRaw(object(Request), '1') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 73
  at HttpKernel->handle(object(Request), '1', true) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 509
  at Application->handle(object(Request)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 484
  at Application->run() in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/web/index.php line 49
Run Code Online (Sandbox Code Playgroud)

和:

ResourceNotFoundException:
in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/routing/Symfony/Component/Routing/Matcher/UrlMatcher.php line 81
  at UrlMatcher->match('/prevendita/hello/sadfasdf') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/routing/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php line 30
  at RedirectableUrlMatcher->match('/prevendita/hello/sadfasdf') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/LazyUrlMatcher.php line 51
  at LazyUrlMatcher->match('/prevendita/hello/sadfasdf') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php line 78
  at RouterListener->onKernelRequest(object(GetResponseEvent))
  at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 164
  at EventDispatcher->doDispatch(array(array(object(Application), 'onEarlyKernelRequest'), array(object(SessionServiceProvider), 'onEarlyKernelRequest'), array(object(RouterListener), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(Application), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php line 53
  at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 110
  at HttpKernel->handleRaw(object(Request), '1') in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 73
  at HttpKernel->handle(object(Request), '1', true) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 509
  at Application->handle(object(Request)) in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/vendor/silex/silex/src/Silex/Application.php line 484
  at Application->run() in /var/www/vhosts/teatrodellamemoria.it/httpdocs/assets/modules/prevendita/web/index.php line 49
Run Code Online (Sandbox Code Playgroud)

这是代码:

<?php
require_once __DIR__.'/../vendor/autoload.php';

use Teatro\Models\Reservation;
use Teatro\Models\ReservationsSeat;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Form\FormError;

$app = new Silex\Application();
$app['debug'] = true;

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/../views',
));
$app->register(
    new Silex\Provider\UrlGeneratorServiceProvider()
);
$app->register(
    new Silex\Provider\SessionServiceProvider(), array(
//        'session.storage.options' => array('name' => 'test')
    )
);
$app->register(
    new Silex\Provider\FormServiceProvider()
);
$app->register(
    new Silex\Provider\ValidatorServiceProvider()
);
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
    'translator.messages' => array(),
));
$app->register(
    new Silex\Provider\SwiftmailerServiceProvider()
);

$app->get('/prevendita/hello/{name}/', function ($name) use ($app) {
    return "Hello $name!";
})->bind('hello_name');

$app->get('/prevendita/hello', function () use ($app) {
    return "Hello!";
})->bind('hello');

$app->run();
Run Code Online (Sandbox Code Playgroud)

开发服务器是PHP 5.4内置的webserver生产服务器是PHP 5.3 CentOS

.htaccess文件基本相同.在生产环境中,silex应用程序进入文件根目录的子文件夹,例如/ prevendita,所以我添加了

RewriteRule ^prevendita /prevendita/web/index.php [L]
Run Code Online (Sandbox Code Playgroud)

将以/ prevendita开头的任何请求重定向到我的silex应用程序

Flo*_*ent 8

你写了:

/prevendita/hello/{name}/
Run Code Online (Sandbox Code Playgroud)

但要求:

/prevendita/hello/sadfasdf
Run Code Online (Sandbox Code Playgroud)

你忘记了斜线.
我认为这就是问题所在.

编辑:根据Fabien Potencier(Silex的作者):

  • 每个资源必须具有唯一的URL(因此/foo/不同/foo).
  • 为了方便最终用户(不是开发人员),当URL必须以a结尾时/,如果他忘记键入它,Silex会将他重定向到正确的URL(带有a /),而不是返回a 404.
  • 当Silex生成URL时,它们总是使用规范URL,因此只有当用户手动输入URL并忘记添加尾部时才会进行重定向/,但框架本身从不使用它.