开发者

Suitable HTTP Status Code

My web application uses ajax and i check request is ajax request or not via php codes. If not then i generate 404 error otherwise run p开发者_如何学JAVAhp codes that associated ajax function.

If user or search spider tries to reach ajax function page(ex: /books/ajax/books_list) web app return 404 not found status code and i see a lot of 404 errors in google webmaster tools.

I should change 404 status code but which one is right for this condition ? Can be "406 not acceptable" ?


I think 403 (Forbidden) probably best describes it. The resource is there, but you've determined that you're not going to give access to that resource, and even authenticating the user isn't going to help.


I would suggest that you return the 406 you suggested. The only alternatives worth considering are '501 not implemented'

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

And '403 Forbidden'

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. 


Not sure how you determine whether it's a proper Ajax request. If you expect it to be POST, but the spider uses GET, then it should be 405 (Method Not Allowed).

You should not be using 406: it means "not acceptable", in the sense that you cannot support the HTTP Accept: headers that the browser sent. This would likely be incorrect (as you likely aren't checking the Accept headers at all).

If you really reject the request because it comes from an unauthorized client, then 403 is appropriate.


It's my understanding that SE spiders get a little skittish if they see errors that indicate server problems. (A 406 can indicate a badly implemented server.) A 404 doesn't describe what you're looking for, as the resource is there, but a 403 (forbidden) just lets the spider know that this page isn't for them. You can also use your robots.txt file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜