Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A web page that requires login should redirect to the login page or simply display the form?

When a web page offers content that require the user to log in there are two ways to have them authenticate themselves:

  1. The web application stores the URL, then redirects to a separate login page, then upon a successful authentication it redirects back to the stored URL;

  2. Instead of the protected content the page displays the login form (staying at the same URL), and after a successful login action the page refreshes and the real content appears.

I'd like to know the following:

  • If I go with option 1 what would be the correct http status code to use? (302 is probably the correct one, so I am listing this question here only for the sake of completeness.)
  • What would be the appropriate http status code for option 2? 401 is tempting but I don't wish to use http authentication.
    • A sub-question: why is http authentication so uncommon?
  • How can I ensure that crawlers won't associate the protected content's title, keywords, description and other meta data with the login form?

And actually this is what I'd really like to know:

  • Do http status codes matter in above cases at all? Are there any pragmatic benefits from using proper status codes?
like image 670
Wabbitseason Avatar asked May 26 '12 08:05

Wabbitseason


People also ask

How do I redirect a login page?

To redirect users to a specific page after login, you can simply add the redirect URL parameter in login form Shortcode. The redirect_url parameter allows you to redirect to a certain page after the user is logged in.

How do I redirect another page when the login button is clicked?

The first way through which you can redirect from one page to another is by clicking a button. You can use a form for this purpose. The form tag in HTML has an attribute action where you can give the URL of the webpage, where you want the form button to redirect. The form tag also has another attribute method.


1 Answers

You want to use option 1. The reason for this is if you show the form on every URL that requires a login you'll have two problems:

  1. The search engines will think the login form is the actual content of that URL instead of the real content. Obviously that is not what you want.
  2. Google will see all of these pages duplicate content which is a bad thing. Their Panda algorithm specifically targets lots of duplicate content and this could result in your site as a whole being penalized for low quality content.

Using a 302 redirect would be the correct way to do this as you have already discovered. And using the proper status codes does matter. Search engines interpret their meaning and sending the wrong status code could cause negative consequences. Since sending the proper HTTP status code is easy to do it definitely is worth doing.

like image 78
John Conde Avatar answered Sep 29 '22 03:09

John Conde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!