Dart 中如何使用 HTTP 服务器完成 404 重定向?
伪代码:
server.addRequestHandler(notFound, redirectTo(...));
提前致谢。
Dart 中如何使用 HTTP 服务器完成 404 重定向?
伪代码:
server.addRequestHandler(notFound, redirectTo(...));
提前致谢。
如果要进行URL 重定向,可以使用:
Refresh
标题:server.addRequestHandler(notFound, (HttpRequest request, HttpResponse response) {
response.statusCode = HttpStatus.NOT_FOUND;
response.headers.set("Refresh", "0; url=http://www.example.com/");
response.outputStream.close();
});
server.addRequestHandler(notFound, (HttpRequest request, HttpResponse response) {
response.statusCode = HttpStatus.NOT_FOUND;
response.headers.set(HttpHeaders.CONTENT_TYPE, 'text/html');
response.outputStream.writeString(
'<!DOCTYPE html>'
'<meta http-equiv="Refresh" content="5; url=\'http://example.com/\'">'
'Page requested cannot be found. You will be redirected in few seconds...'
);
response.outputStream.close();
});