4

I have a website on which users can ask a question, but in order to ask a question they must be logged in.

Which means if users go to the URL example.com/ask-question/, then it will redirect them to login page example.com/login/?next=/ask-question/.

Problem is that Google has not only indexed the login page (example.com/login/) but also it has indexed the ask question page as login page. As a result, now we have two login pages in search results where one is direct login and the other is a redirect.

I want to remove the login redirect page from search results. How can I do that?

  • At the load of /ask-question/, check if the user is logged in. If not redirect (301) to /login/. If you will do so then you will not have to do anything. Google will remove /ask-question/ from the index. it needs to be 301. – TopQnA May 26 '18 at 12:01
  • @TopQnA I rather suspect that the OP is using a 301 redirect already and why the ask questions page is being confused for a login page. Instead, I suspect the OP should be using a 302 instead. – closetnoc May 26 '18 at 17:23
  • Maybe you could change it so they could ask a question and THEN log in. You don't need to be logged in to type your question in, you just need to be logged in to get it posted to the site. – Stephen Ostermiller May 27 '18 at 10:11
4

Here is a simple solution if you want to keep indexed your login page and remove all other redirected login page variations from Google.

First of all, hope that you are using 302 redirect in this case which is not cachable in browsers and is as temporary. This is just a note.

To keep only your login page indexed in Google, you must use proper canonical link tag in your login page and Google will index only that URL what you include in the canonical link tag. Example:

<link rel="canonical" href="https://example.com/login/" />

This canonical link tag must be in all of your mentioned URLs source code, i.e example.com/login/?next=/ask-question/ and example.com/login/

In this case, Google will index only that URL which is in the canonical link tag.

-1

...Which means if a user go to the URL www.website.com/ask-question/, then it will redirect them to login page www.website.com/login/?next=/ask-question/.

The best way to go is to modify your server code so that when a user who isn't logged in (including search engine robots) tries to access www.website.com/ask-question/, the returned HTTP code will be 301 (which means moved permanently) and the location in the header will become www.website.com/login/?next=/ask-question/.

To verify if you constructed your redirect properly, go to https://redbot.org and enter http://www.website.com/ask-question/ and the first 11 characters in the black box that appears should be the following if your server uses HTTP 1.x:

HTTP/1.1 301

Then somewhere in that box, you should see a line that starts with "Location:" with "http://www.website.com/login/?next=/ask-question/"

Change "http://" to "https://" in all cases if all webpages on your server use SSL (which most seem to do these days).

The advantage to this is that just about any web browser will transparently handle the redirect for you so the end user will think that only one page is loaded. Also, Search engines never index pages that return the HTTP 301 status code as they offer no value. And third, if a user decides to bookmark the page, then only one easy URL will represent the page.

  • Forgive me, I am confused. I am not sure the OP want to always redirect, but do so when the user is logged on and the existing 301as part of that process is indexing the login page and not the ask question page. It reads to me that you are almost advising what he conditionally does already. BTW- How's it? Doing okay? Cheers!! – closetnoc May 26 '18 at 21:13
  • Browsers cache 301 redirect aggressively. If you have a page to which the user is expected to return after logging, in, a 301 redirect won't work. The browser won't fetch the URL again, just get the redirect from cache. The user will be caught in an endless redirect loop. 302 temporary redirects are the correct type of redirect in this particular situation. – Stephen Ostermiller May 27 '18 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy