在 Web 应用程序中处理未知 URL 的最佳实践是什么?
What are best practices for handling unknown URLs in a web application?
我有一个由 Angular Fullstack Generator 生成的 Web 应用程序。如果 ExpressJS 服务器收到对某些特定目录的未知 URL 的请求,它将 return 404:
app.route('/:url(api|auth|components|app|bower_components|assets)/*')
.get(errors[404]);
对于所有其他未知路由,它只是重定向到主页:
app.route('/*')
.get(function(req, res) {
res.sendfile(path.resolve(app.get('appPath') + '/index.html'));
});
这是个好主意吗?我问的原因是因为 Google 报告我的网站可能被黑客入侵。它一直尝试像 http://andrewkoroluk.com/survival-games-1-e7733-map 一样获取 URLS,当它收到 200 OK 响应时,它会标记该站点。
HTTP 的 RFC 声明您必须 return 404 未找到。
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5
这不是好事也不是坏事,这是强制性的
我有一个由 Angular Fullstack Generator 生成的 Web 应用程序。如果 ExpressJS 服务器收到对某些特定目录的未知 URL 的请求,它将 return 404:
app.route('/:url(api|auth|components|app|bower_components|assets)/*')
.get(errors[404]);
对于所有其他未知路由,它只是重定向到主页:
app.route('/*')
.get(function(req, res) {
res.sendfile(path.resolve(app.get('appPath') + '/index.html'));
});
这是个好主意吗?我问的原因是因为 Google 报告我的网站可能被黑客入侵。它一直尝试像 http://andrewkoroluk.com/survival-games-1-e7733-map 一样获取 URLS,当它收到 200 OK 响应时,它会标记该站点。
HTTP 的 RFC 声明您必须 return 404 未找到。
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5
这不是好事也不是坏事,这是强制性的