【问题标题】:Disable '/' route in Silex在 Silex 中禁用“/”路由
【发布时间】:2017-02-20 10:03:06
【问题描述】:

我需要禁用 silex 主路由/,我的意思是,当你进入我的应用程序的主页时,服务器必须响应 404。我可以更改有关路由的配置,以避免这样做。

代码

app->get('/', fucntion() use($app){
   return new Response('Oops ... ', 404);
});

当我进入网络应用程序时,在主路由中服务器会响应我这样的信息。

错误

NotFoundHttpException in RouterListener.php line 125:
No route found for "GET /" (from "http://localhost/projects/")
in RouterListener.php line 125
at RouterListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(EventDispatcher))
at call_user_func(array(object(RouterListener), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(EventDispatcher)) in EventDispatcher.php line 174
at EventDispatcher->doDispatch(array(array(object(RouterListener), 'onKernelRequest'), array(object(MiddlewareListener), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent)) in EventDispatcher.php line 43
at EventDispatcher->dispatch('kernel.request', object(GetResponseEvent)) in HttpKernel.php line 129
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 496
at Application->handle(object(Request)) in Application.php line 477
at Application->run() in index.php line 8

总结

我可以禁用主路由 / 吗?我可以禁用 RouterListener 以避免此类错误吗?

谢谢。

【问题讨论】:

  • app->get('/', fucntion() use($app){ 语法错误 -> 函数。

标签: php silex


【解决方案1】:

如果您不为/ 创建路由,silex 将响应 404,就这么简单。

您得到的是调试页面,因为您的应用程序正在调试模式下运行。关闭它,您将获得一个没有信息泄漏的简单 404 页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多