3

Which HTTP redirect status code is the best for redirect a webpage to the mobile version?

From: www.example.com

To: m.example.com

Wiliam
  • 3,714
  • 7
  • 36
  • 56

2 Answers2

6

I would send a 301 while using Vary to specify the request header fields that lead to this server-driven negotiation decision.

So, assuming that the User-Agent header field is used to distinguish whether the request was made by a mobile device, I would use this:

HTTP/1.1 301 Moved Permanently
Vary: User-Agent
Location: http://m.example.com/...
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • The Google guidelines suggest that the "vary" header should be on the 200 response, rather than the 301 response. https://developers.google.com/webmasters/smartphone-sites/redirects – Spongeboy Jan 22 '13 at 06:21
  • 1
    @Spongeboy “If your site serves content or redirects users depending on the user-agent, i.e. the response varies, we strongly recommend that your server *also* send the Vary HTTP header on URLs that serve automatic redirects.” Note the emphasized “also”. – Gumbo Jan 22 '13 at 17:19
  • well spotted! Using 'vary' seems like the most graceful solution, but seens hard to implement in IIS URL Rewrite (which is what I'm using for redirects). – Spongeboy Jan 23 '13 at 12:39
  • @Gumbo why a 301 in this case instead of a 302? Both URLs are valid right? – Explosion Pills Mar 21 '13 at 22:26
4

A temporary redirection (302 or 307) should be sufficient for this.

The Google guidelines for smartphone site redirections states-

For this purpose, it does not matter if the server redirects with an HTTP 301 or a 302 status code.

As such, a 302 is probably preferable over 307.

The guidelines suggest that the "vary" header should be part of the 200 response.

Spongeboy
  • 2,232
  • 3
  • 28
  • 37
  • Im sure this probably just changed since you made this post but the quote you made from the google guidelines is followed by another sentence that states 302 is preferable by google when possible. "For this purpose, it does not matter if the server redirects with an HTTP 301 or a 302 status code, but use of 302 is recommended whenever possible." – naw103 Apr 08 '15 at 13:56