On my staging subdomain I want to make the canonical URL for each page the URL of the page on my main site. My CMS is WordPress.
I want to do this so that if Google crawls my staging site I won't risk pages on my main site losing rankings because of duplicate content.
Ex: on staging.example.com
<link rel="canonical" href="example.com/{the-page}" />
Canonical URLs on my website are being set with the Yoast SEO Wordpress Plugin.
How can I accomplish this?
no-index
was was set as well?noindex
because I try to keep my staging server and my live site as much the same as possible. I try to avoidif (staging){...
because I find it error-prone. That especially goes for things that aren't immediately obvious and visible such as meta tags. I was just using canonical tags because those tags would be identical on the staging and live servers with my domain name hardcoded in them.