Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST: Is http code 300 appropriate in this redirect situation?

I have a multi-locales website. I need to redirect users to their locale when they access the site without the locale code in the url.

e.g.

http://www.mysite.com automatically redirected to either http://www.mysite.com/uk or http://www.mysite.com/us

I'm looking at rfc2616 and I'm hesitating to use Code 300 (Multiple Choices):

The requested resource corresponds to any one of a set of representations, each with its own specific location, and agent- driven negotiation information (section 12) is being provided so that the user (or user agent) can select a preferred representation and redirect its request to that location.

Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field.

Depending upon the format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed automatically. However, this specification does not define any standard for such automatic selection.

If the server has a preferred choice of representation, it SHOULD include the specific URI for that representation in the Location field;

I think I understand, but the wording still makes it a bit cryptic for me. Can someone familiar with response codes confirm if I'm on the right track and explain the following excerpts?

  • [...] and agent-driven negotiation information is being provided [...]
  • Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s) [...]
  • like image 906
    Michael Ekoka Avatar asked Nov 17 '10 20:11

    Michael Ekoka


    1 Answers

    In your case I don't think you want "agent driven negotiation". In your case, your server should be able to select the redirect location from the accept-lang header. I think you can use the 303 redirect.

    Agent driven negotiation is only used when the server does not know what the representation the client wants. In those cases, the server would return a list of links with the different options available. The agent would then select representation it wants.

    You would use agent driven negotiation if you wanted some javascript code to process the 300 response and display a list of options to the user so that the user can select the desired language.

    like image 140
    Darrel Miller Avatar answered Oct 02 '22 16:10

    Darrel Miller