Hello,
We apologize for the issue you are facing with the canonical URLs in Rank Math. To ensure that Rank Math displays the primary domain instead of the subdomain, you can set the canonical URL manually in the Rank Math meta box for each page or post.
Here’s how you can do it:
- Edit the page or post where you want to change the canonical URL.
- In the Rank Math meta box, navigate to the Advanced tab.
- In the Canonical URL field, enter your primary domain URL (e.g., `https://www.siteground.com/kb/how_to_redirect_www_urls_to_nonwww/).
- After making the changes, make sure to update or publish the page.
This will inform search crawlers of the main source of your content and should resolve the issue with the canonical URLs appearing as the subdomain.
If you have multiple pages to update, you may need to do this for each one individually. Unfortunately, there isn’t a global setting in Rank Math to automatically change all canonicals from a subdomain to a primary domain.
If you continue to experience issues or have further questions, please feel free to reply to this ticket, and a human agent from our support team will assist you further.
Thank you for raising this concern!
Sources:
Alternate Page with Proper Canonical Tag Status in Google Search Console » Rank Math
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hello,
Thank you for your query and we are so sorry about the trouble this must have caused.
This happens because Rank Math depends on the Site address set forth by your WordPress settings.
To fix this, you can make use of the code below:
add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
// Change the domain names accordingly
return str_replace( 'prod.website.com.au', 'www.website.com.au', $canonical );
});
You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how that goes. Looking forward to helping you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.