如果照片#123不存在,我应该向/photo.php?id=123这样的请求扔404吗? [英] Should I throw a 404 to a request like /photo.php?id=123 if photo #123 does not exist?

查看:96
本文介绍了如果照片#123不存在,我应该向/photo.php?id=123这样的请求扔404吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该脚本将从URL < example.com/photo.php?id=123 或 example.com/photos/123

The script will be called from a URL like example.com/photo.php?id=123 or example.com/photos/123 depending on if the have the pretty URLs featured enabled.

如果照片#123不存在,则请求 example.com/photos/123 应该会引发404错误。但是,关于 example.com/photo.php?id=123

If photo #123 does not exist, a request to example.com/photos/123 should throw a 404 error. But, what about example.com/photo.php?id=123?

推荐答案

相关的RFC是2616,特别是有关状态代码< a>,请求 URIs 。具体来说,查询字符串被认为是URI的 part ,所以 404 是正确的响应,因为它意味着:

The relevant RFC is 2616, specifically the sections on status codes, requests, and URIs. Specifically, the query string is considered part of the URI, so a 404 is the proper response since it means:


服务器没有找到与Request-URI匹配的任何

The server has not found anything matching the Request-URI.

如果您知道照片已被永久删除,您可以返回 410

If you can know that a photo has been permanently deleted, you may return 410.

I不会返回 200 ,并说找不到结果。

I would not return 200 and say "no results found."

这篇关于如果照片#123不存在,我应该向/photo.php?id=123这样的请求扔404吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆