Description. Page to which users are automatically redirected after completing a successful authentication.
The role of the 302 redirect in SEO By default, a 302 redirect passes no page authority from the old URL to a new URL. 302 redirects are rarely used, since in most cases you want to pass a page's authority, and only a 301 redirect will let you do that.
200 is the normal response given for a web page. It is the equivalent of you dialing a phone number and the other person answering. 301 is the normal method to redirect a user to a different page. It is the equivalent of call forwarding.
The most common ways to implement redirection logic after login are: using HTTP Referer header. saving the original request in the session. appending original URL to the redirected login URL.
I'd say 303 see other 302 Found:
The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.
fits a login page most closely in my opinion. I initially considered 303 see other
which would work just as well. After some thought, I'd say 302 Found
is more fitting because the requested resource was found, there just is another page to go through before it can be accessed. The response doesn't get cached by default which is fine as well.
This is a misuse of HTTP redirection mechanism. If user is not authorized then your app must return 401 Unauthorized
. In case that the user is authorized but does not have an access to the requested resource then 403 Forbidden
must be returned.
You should do the redirect on client side, e.g. by javascript. status code for redirection because required authorization does not exist. Using 30x for this does not conform to HTTP.
How to Think About HTTP Status Codes by Mark Nottingham
401 Unauthorized triggers HTTP’s request authentication mechanism.
401 Unauthorized
status code requires presence of WWW-Authenticate
header that supports various authentication types:
WWW-Authenticate: <type> realm=<realm>
Bearer, OAuth, Basic, Digest, Cookie, etc
I think the appropriate solution is the HTTP 401 (Not Authorized) header.
http://en.wikipedia.org/wiki/HTTP_codes#4xx_Client_Error
The purpose of this header is exactly this. But, instead of redirecting to a login page, the correct process would be something like:
This is a good practice, like providing a useful 404 page, with sitemap links, and a search form for example.
See you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With