Specify a Canonical URL

Facebook link sharing allows you to specify a canonical URL for a resource in the HTML metadata for the resource. This is accomplished by using an HTML meta tag to specify the canonical URL for the page. The canonical URL is specified using the og:url property.

<meta property="og:url" content="https://example.com/path" />

Starting February 3, 2020, you will no longer be able to specify URLs with a different domain as the canonical URL, unless that domain has explicitly added your domain to an allow list using the Webmaster tool.

All links that specify the same canonical URL are treated as the same resource by Facebook's link sharing infrastructure for the purpose of metrics and metadata (link image, title, etc.). You can view engagement metrics for a URL using the Graph API call:

GET /?id={your_url}&fields=engagement

There are a number of scenarios where it might be useful to treat various links on your site as identical. Here are a few examples:

  • You change the URL for a page but don't want to lose the previous metrics.
  • You provide links to versioned content, but for the purpose of metrics, you treat the content as a single page.
  • You want Facebook to de-duplicate similar links, when displaying them on any surface.

Additional Considerations

  • The path specified for og:url does not need to be a page that renders in the browser. However, it must respond to the Facebook crawler and return og:* meta tags. For details on detecting the Facebook crawler, see The Facebook Crawler.
  • When the path referred to by og:url returns an og:url link that is different, the new link is followed. The sharing details that Facebook uses are the ones at the final link in the redirect chain. The final link in the chain should also include the og:url meta tag. If og:url isn't specified, then the URL of the page is assumed to be the canonical URL.

How to Preserve Engagement Metrics when Changing a URL

The following example demonstrates how to change the URL for a page while preserving the Facebook share link and related metrics. It assumes that the URL for the page has already been changed.

  1. Use an HTTP 301 or 302 redirect to send visitors to the new URL when they visit the old one. The crawler still needs access to the old URL, so exempt the crawler's user agent from the redirect action and only redirect non-Facebook crawler clients. For more information on detecting the Facebook Crawler, see Sharing Best Practices - Crawler.
  2. Open the new page and add the og:url tag. Set the content attribute to the previous URL value.
  3. <meta property="og:url" content="your_old_url" />
  4. Create a new page at the old URL and add the following header meta tags:
  5. <!-- This is the URL for this page -->
    <meta property="og:url" content="your_old_url" />
    
    <!-- This is the og:* meta from the original version of the page -->
    <meta property="og:title" content="your_link_title">
    <meta property="og:image" content="your_image_url">
  6. Publish your content and then use the Sharing Debugger to verify that your server is returning the correct metadata for each of your URLs.

    Open the Sharing Debugger