Search engines recorded referrals from links like this: http://subdomain1.example.com, http://subdomain2.example.com. Subdomain pages display the contents of main domain pages but subdomains do not exist. CMS writes canonical link with subdomain address for subdomain page and with domain address for main domain page.Is the correct solution for SEO to set 301 redirect from non-existent subdomains on main domain or can I just rewrite href attribute in canonical link before output for subdomain pages?
Redirect from non-existent subdomains is correct?
seo;subdomain;canonical url
Setting the correct canonical URL in the link element should be sufficient (although you might need to verify these non-existent subdomains in Google Search Console?), however, it would be preferable to set a 301 redirect which will catch users as well and prevent them linking to the wrong domain, etc.This sort of redirect can be (should be) included as part of your canonical (www / non-www) redirect.For example, to redirect all requests that are not for your canonical domain (eg. example.com) to your canonical domain then you can do something like the following in your server config, or .htaccess:RewriteEngine OnRewriteCond %{HTTP_HOST} !=example.comRewriteRule .* http://example.com/$0 [R=301,L]