【发布时间】:2016-07-17 21:56:31
【问题描述】:
当我手动输入错误的 url 时,我的 .htaccess 工作正常,它重定向到我的自定义 404 页面。这是我的 .htaccess(这是漏洞内容(没有其他重定向)):
RewriteEngine on
ErrorDocument 404 http://codeexample.local/404.shtml
现在在我基于 Silex 的应用程序中,如果客户端尝试编辑不存在的客户端,我会返回 404 状态代码。即使状态码确实是 404,我可以使用 curl -v 看到。但由于某种原因,它没有被重定向到 404 错误页面。
这是我访问网址的方式:
http://codeexample.local/index.php/2/edit
这是我的 index.php 编辑路线部分:
$app->match('/{id}/edit', function (Request $request, $id) use ($app) {
try {
$clientController = new ClientController($request, $id);
return $clientController->editAction($app);
}
catch(\Exception $e){
return $e->getMessage();
}
})
->assert('id', '\d+')
->method('GET|POST');
在我的 editAction 方法中,我正在检查客户端是否存在于数据库中,否则我将返回如下响应:
$response = new Response(
'',
Response::HTTP_NOT_FOUND,
array('content-type' => 'text/html')
);
$response->prepare($request);
$response->send();
return $response;
谢谢
【问题讨论】: