I have one login page but on google I see it duplicated. My website has login link in every post and the link is always followed by post id (it is to save the post so the user can get back to the post after loging in or registering)

For example, let's say there is a page that shows post number 50, so the login link whould be like : login.php?post_id=50, but here google index each login.php with a different id as a new link while i want the login page to be indexed only once as login.php.


1 Answer 1


If you have tons of these login links (like a different one from every page on your site), you don't want Googlebot to crawl all the variations. That would be too much unnecessary crawling that could eat up the crawl budget for your site. Googlebot might not be able to crawl all the pages you want them to crawl and index. In that case, you should disallow the variants using robots.txt.

User-Agent: *
Disallow: /login.php?

Including the question mark at the end of the disallow rule prevents Google from crawling any login link with URL parameters, but would allow crawling the version without parameters. Because Google won't be able to crawl them, Google won't index them unless a variation gets several external links.

The second thing that you can do is prevent Googlebot from finding the URLs with the parameters by appending the parameters dynamically using the onclick event. Even when Google executes JavaScript, it doesn't simulate clicking on anything. Anything that happens on a click is effectively invisible to Googlebot. You could link to the login like this:

<a href=/login.php onclick="this.href+='?post_id=50'">Log in</a>

The third thing that you can do is include /login.php in your XML sitemap but NOT /login.php?post_id=50 or any other variants. When you include a URL in your sitemap, Google uses that as a signal that that version of the URL is the correct and important one that you want indexed.

The last option is to allow the URLs to be crawled, but use a canonical tag in the <head> of the login page:

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

This canonical tag would always point to the version of the login page without parameters. When Googlebot crawls a variation of the login page, it would find the canonical tag and know that you would prefer that the version without the parameter get indexed instead. Note that this solution is not compatible with the robots.txt solution. If Googlebot can't crawl the URL, it can't see this tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.