对于“未找到项目”,最合适的HTTP状态代码是什么?错误页面
我很好奇什么是项目不存在页面最合适的HTTP状态代码。
I'm curious what's the most appropriate HTTP status code for an "item does not exist" page.
如果页面本身不存在,我' ll显然使用404.但是,我的一个页面有一个 userid
参数(它是一个编辑用户页面),如果没有给定用户ID的用户,我'我显示错误页面,但我也想发送一个4xx状态标题(因为200 OK不适合)。
If the page itself doesn't exist, I'll obviously use 404. However, one of my pages has a userid
argument (it's an "edit user" page) and in case no user with the given user ID exists I'm displaying an error page, but I'd also like to send a 4xx status header (since "200 OK" doesn't really fit).
我想404会没关系,因为它找不到而不是找不到文件,但我想知道这个案例是否有更好的代码。
I guess 404 would be ok since it's "not found" and not "file not found", but I wonder if there's a better code for this case.
使用模糊的HTTP错误代码过于聪明是一个坏主意。浏览器有时会以无助的方式做出反应,使情况模糊不清。坚持使用404.
Getting overly clever with obscure-er HTTP error codes is a bad idea. Browsers sometimes react in unhelpful ways that obfuscate the situation. Stick with 404.