How to set og:url correctly to the canonical, public URL of this page?

og-url-canonical-mismatch page

The issue

A page whose og:url differs from its canonical has its shares counted against an address that isn’t the page’s own. Facebook aggregates likes and shares at the og:url, so a page shared under two addresses splits its count between them. The link may also send people to the variant rather than the page.

The cause is usually a template that builds og:url from the requested URL, tracking parameters and all, while the canonical is built from the page’s clean address.

Scope

Each page declares its own og:url and its own canonical. They are compared for that page only.

How to check you have it

  • In probeo: a page without og:url reports Missing og:url, as a warning. Probeo doesn’t compare og:url with the canonical, so check that by hand.
  • By hand: view the page source and compare the content of og:url with the href of <link rel="canonical">. They should be identical, character for character.
  • With a tool: Facebook’s Sharing Debugger shows the URL it treats as canonical for the page.

The fix

Set og:url to the same URL as the page’s canonical.

Generate both from one value in the template, so they can’t drift apart. Use the clean, absolute HTTPS address, without tracking parameters or session values. If the page has no canonical tag, use the public HTTPS URL it is served at.

Done when: og:url and the canonical are the same URL on every page, and the check above comes back clean.

Do not

  • Do not set og:url to a URL that redirects.
  • Do not include tracking parameters that aren’t part of the canonical.
  • Do not use a relative URL.

FAQ

What happens if og:url points to a URL that redirects to the canonical URL?

Then the page names two addresses: the redirecting one in og:url and the destination in its canonical. Point og:url at the final URL so there is only one.

Should og:url include query parameters if the canonical URL does not?

No. Parameters the canonical leaves out make a second address for the same page.

Does og:url need to match the URL in the browser address bar?

No. The address bar can hold tracking parameters or session values. og:url should match the canonical, the clean address.

What if the canonical URL changes after the page has been shared?

Earlier shares keep the old address. Keep the canonical stable after publishing, and redirect the old URL if it has to change.

Can og:url point to a different domain than the canonical URL?

Only if the canonical does too. Content republished from elsewhere may name its original home in both. Otherwise they belong to the same domain and path.

How do social platforms use og:url when the page is shared?

Facebook treats it as the page’s canonical URL and aggregates likes and shares there. Other platforms don’t document their use in detail, which is reason enough to make it the same as the canonical.

Which product detects this

Probeo checks this on every page of your site as part of Site Clarity. This page explains one instance; the product tells you every page that has it.