I'm setting up redirection for mobile/non-mobile pages. User agent is detected and redirected appropriately, but the ?mobile=1
or ?mobile=0
flag can be used to force a switch. When that flag is used, I always do a 301 redirect because the ?mobile=
links should not be indexed, just their targets. Is this a correct assumption?
Additionally, there is the case of redirection by trying to visit the mobile link /m
with a non-mobile user agent and vice versa. In this case I want to do a 301 redirect as well (mostly because it makes the code simpler), but I think it also makes sense to me semantically; the target URL for your user agent is the correct one.
A coworker is insisting that /m
visits by a non-mobile user agent should do a 302 redirect because the /m
link is valid. However, the only way to make it valid is to either visit ?mobile=1
at the same time (which would already do a 301 redirect to /m
) or to have something else on our website that sets the session to mobile, which is something we either rarely or never do.
Google's documentation seems to indicate that it actually doesn't matter if you use 302 or 301 for mobile/non-mobile redirection (at least if you have the Vary: User-Agent
header and/or rel="alternate"
link specification; we currently have neither, though).
My arguments for the 301 are:
- Simplifies the code a bit
- Non-mobile spiders will not index the
/m
link, so theoretically it should not show up for search results which spares non-mobile users an additional redirect when they visit the link (similar situation for mobile spiders/users)
However, he does have a point about both of the URLs being valid. Which status code would be better to use in this case?