I have to build two websites: one for the staging and another one for the production. and both are hosted on the server, but when I search on google with the website name, both websites are comes together, and the staging one comes before the production website, I just want that when I find the website by the name only the production one will come, I do not want to show my staging website to visitors. Both websites are built in the next.js. There would be any way to handle to SEO of the production website or reduce the rank of my staging website.
-
Do the production and staging sites use different host names (different domains or subdomains)?– Stephen Ostermiller on Strike ♦Jul 22, 2022 at 8:43
-
But I have already hosted the website and with the name- XYZ-staging.com and xyz.com, so now how what I can do for this ...– Lokesh SharmaJul 22, 2022 at 9:23
-
1Can't you just ban google bot in your robots.txt file– Rohit GuptaJul 22, 2022 at 9:43
-
Does it also affect the production site ??– Lokesh SharmaJul 22, 2022 at 10:16
1 Answer
Long-term solution
(Assuming you are using Apache. Equivalent solutions exist for other web servers.) Any of these solutions is fine:
- Use htpasswd to only expose the website to users with the credentials.
- Use the htaccess to limit access to the staging site to a specific IP range.
- Use the htaccess to limit access to a specific user agent. Use a browser plugin to change your user agent to this specific one.
These three solutions are all good for privacy and security. You will probably not want anybody to just click around on your staging site. And all three solutions prevent Google bot from crawling your site.
Pick the solution that best fits your use case. If you do not have a static IP address or have a lot of coworker and stakeholders who need access to the staging site, some of these solutions might not be very convenient for you.
Short-term solution
Since Google already indexed your site, you should first do this:
- Authenticate your staging site in Google Search Console.
- In Google Search Console, manually remove the URLs that Google Bot has crawled so far from the Google Index.
- Add the robots-noindex meta tag to all documents on the staging site. That means the next time Google crawls them, they will be removed from the index.
In theory, step 3 alone would be enough. Steps 1 and 2 just help to speed up the process.
Once Google has no more pages of your staging site in the index (or only has them in the index without any content, saying "No information is available for this page."), activate one of the long-term measures.
If none of the long-term solutions work, you could, in theory, stick with having robots-noindex everywhere on the staging site. Google would never show the site in search results. However, your competitors or hackers might find it.
Additional concerns
- Make sure the robots-noindex from the staging site never make it to the production site. You would - temporarily - lose all your Google rankings.
- Make sure there are no links from your production site to the staging site. You should crawl the production site with a tool like Screamign Frog and make sure all links, canonical, hreflang, alt, etc., always go to the production site and never to the staging site.
-
1It sounds like part of the question is how do you use the same code for both production and staging while keeping Google back just off just the staging site Jul 23, 2022 at 15:42