The following EdgeRule will apply a canonical tag, commonly used for Search Engine Optimization (SEO) to assist with page indexing by search engine crawlers. This is an ideal rule if a site is using a Static Assets integration.
If you have not already, please check this guide to get started.
Creating the Rule
- Click the Sites menu on the left and select the Site you would like to create the rule for
- Navigate to your EdgeRules tab
- Select Add Delivery Rule
- In the initial IF Option, please select the URL option and select the Matches setting, and add in
*://cdn.url/*
. Also, please replace "cdn.url" with your actual CDN URL. - In the THEN option, select Add Response Header and add
Link: <https://yourdomain.com%client.request.fullfilepath%>; rel="canonical"
. Replacing "yourdomain.com" with your actual domain.
By setting a URL "Matches" condition to match to your Edge Address, this rule will apply the Link: <https://www.yourdomain.com/file/path> rel="canonical" header to all CDN assets. You can optionally replace the Edge Address with your desired Delivery Domain. Remember to replace www.yourdomain.com with your actual domain, as well.
Verifying the Rule
This rule adds a public response header to the CDN Response. Verify it by checking the headers from CDN assets using browser inspect tools or cURL requests.
For browser tools, right-click anywhere on your website and select inspect or inspect element and navigate to the network tab. If you do not see any requests, refresh the page with this tab open to view them as they come in.
You can select any of the assets coming from your CND URL to view the request headers, and verify that the rel ="canonical" appears in the header list, similar to the example below.
When performing a cURL test, the option -I is important to include in order to see the headers appropriately. Below is an example of a curl, with the rel="canonical" header highlighted.
If you have any questions or would like assistance setting up this rule, feel free to contact StackPath's 24/7 live support, we'll be happy to help.