我的web应用程序使用ajax,我检查请求是否是通过php代码的ajax请求。如果不是,那么我生成404错误,否则运行php代码关联ajax函数。
如果用户或搜索爬行器试图访问ajax功能页面(例如: /books/ajax/books_list),web应用程序返回404Not found状态码,我在google网站管理员工具中看到很多404错误。
我应该更改404状态码,但是哪一个状态码适合这种情况?可以是"406不可接受“吗?
发布于 2011-01-24 06:15:56
我认为403 (禁止)可能是对它最好的描述。资源是存在的,但您已经确定不会授予对该资源的访问权限,而且即使对用户进行身份验证也无济于事。
发布于 2011-01-24 06:18:48
我建议你退还你建议的406。唯一值得考虑的替代方案是“501未实现”。
The server does not support the functionality required to fulfill the request.
This is the appropriate response when the server does not recognize the request
method and is not capable of supporting it for any resource
和“403禁忌”
The server understood the request, but is refusing to fulfill it.
Authorization will not help and the request SHOULD NOT be repeated.
If the request method was not HEAD and the server wishes to make
public why the request has not been fulfilled, it SHOULD describe
the reason for the refusal in the entity. If the server does not
wish to make this information available to the client, the status
code 404 (Not Found) can be used instead.
发布于 2011-01-24 06:26:01
不确定如何确定它是否是正确的Ajax请求。如果您希望它是POST,但爬行器使用GET,那么它应该是405 (不允许使用方法)。
您不应该使用406:它的意思是“不可接受”,因为您不支持浏览器发送的HTTP Accept:标头。这可能是不正确的(因为您可能根本没有检查Accept标头)。
如果您真的拒绝了请求,因为它来自未经授权的客户端,那么403是合适的。
https://stackoverflow.com/questions/4776898
复制相似问题