Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a website that takes two primary get strings:

?type=GAME&id=SomeGameID
?type=SCENARIO&id=SomeScenarioID

for reasons unknown, I have recently begun receiving requests for erroneous get strings from both Yandex and Baidu. They are always in the form of:

?type=GAME&id=SomeScenarioID

None of my users are triggering these errors, so I am (sort of) confident that this is not due to an HTML template error somewhere on my part. There is also no HTTP_REFER showing up in the $_SERVER array, so I'm guessing these are direct requests from bad dbase data on their part.

I see two options for dealing with these bad requests, and would like to know which is recommended... or if there are other, better options I have not thought of:

  1. simply 404 the request, since it is incorrect
  2. redirect the request to ?type=SCENARIO&id=SomeScenarioID because the scenario IDs are always valid, the breakage is due to asking for the wrong type.
share|improve this question
    
Going by your second solution, why do you even need to specify the type=? If scenario and game IDs are mutually exclusive, there's no need to classify them. However, you may want to use a 404 for security, hindering a user from manually trying to access a game or scenario by guessing ID numbers. –  Hand-E-Food Oct 23 '12 at 1:44
    
@Hand-E-Food - I separate them because they are stored in different tables in the database and have very different properties. By receiving a type my code knows which table to query, and which class to create an object from. It simplifies things for me without adding any overhead to the UX. –  Andrew Heath Oct 23 '12 at 1:58
add comment

3 Answers

up vote 7 down vote accepted

I would stick with rejecting the request, however as the url being requested does exist, the error code 400 seems more appropriate.

From the w3 http/1.1 standards:

10.4.1 400 Bad Request

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

share|improve this answer
    
oooh, code 400, very nice! That will hopefully help them clean up their bad data rather than repeatedly ping for these false links. –  Andrew Heath Oct 23 '12 at 5:19
    
"the url being requested does exist" - no, it clearly does not. URL includes querystring, and the user is requesting a GAME resource which does not exist. Hence, 404 is the correct status code. 400 says the request syntax is bad, which it is not. –  Chris Oct 23 '12 at 19:45
    
@Chris - it is not at all clear cut. You could make an argument that this is a request against a primary URL (which exists!) made with invalid query parameters. The specification of the HTTP response codes is sufficiently rubbery that either 400 or 404 is justifiable. And if this is sufficient to fend off unwanted crawler requests, then that is ample justification ... no matter what the spec says. –  Stephen C Oct 25 '12 at 7:43
    
@StephenC: URL means Uniform Resource Locator. The resource being "located" is a particular game entity which does not exist, so the status code should reflect that. There is nothing "rubbery" about "The request could not be understood by the server due to malformed syntax". This clearly does not describe the issue at hand. I don't see why a crawler would repeat a request that results in 404 and more than it would for 400. However, the 400 error may confuse legitimate users who are actually looking for a game. –  Chris Oct 25 '12 at 14:22
add comment

I would favor 404 over 400 in this situation. 400 means the request is malformed, but the request you described is not malformed. The request is for a GAME that does not exist; this is the definition of error 404.

If there were a way to know: the request is for a GAME, but the ID given is clearly a scenario ID, then this would constitute malformed syntax. However, based on your statements in the comments, there is no discernible difference between game IDs and scenario IDs. The game ID being requested is a valid ID, it simply doesn't exist.

This is the same reason your redirect idea would not be good. You can't know that someone is actually looking for a SCENARIO if they have specifically asked for a GAME. If a consumer asked for a GAME but accidentally passed a bad ID and got redirected to a SCENARIO, they would be terribly confused.

share|improve this answer
add comment

I concur that 400 is a better response than 404.

When you say "I'm guessing these are direct requests from bad dbase data on their part". I interpret that as meaning that the requests are coming from web crawlers. If that is the case, then another alternative would be to configure your site's robots.txt file to tell the Yandex and Baidu crawlers to stay out of the part of your site with the queries. Or maybe just block them.

Assuming that this is crawler activity, the problem might not be bad data (which would have had to come from somewhere). It is possible that the engines are trying alternatives in a rather lame fashion in order to harvest stuff that isn't directly linked. (It sounds like a stupid thing to do, but you never know ...)

On the other hand, if this is not web crawler activity, perhaps it is the result of some users trying to access your site using some custom client rather than using the UI implemented by your web templates. That would also explain the lack of referrer headers.

share|improve this answer
    
it's all crawlers - just Yandex and Baidu so far, not google. –  Andrew Heath Oct 24 '12 at 8:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.