When the same website content is available through both the origin domain and a CDN custom domain, web crawlers can discover and index both URLs. Block crawling on the CDN domain with a dedicated robots.txt response so that compliant crawlers do not crawl that domain.
Create a CDN rule that matches /robots.txt and returns a Disallow: / directive. The rule changes only that response, so other CDN URLs keep serving their configured content while compliant crawlers do not crawl them.
CDN domain crawling
Open the resource and set the path, the status code, and the disallow body.
1
Open the CDN resource
In the CDB Customer Portal, navigate to CDN → CDN resources and click the CNAME of the resource.
2
Start a blank rule
Navigate to the RULES tab.
Click Create rule.
Select Create blank rule.
3
Set the name and path
In the Rule name field, enter Block CDN crawling.
In the Rule pattern field, enter ^/robots\.txt$.
4
Return the disallow text
Click Add option.
Under Content, click Add next to Status code, then close the panel.
In the Status code section, enable the Set status code option.
In the Status code field, enter 200.
In the URL or code text (optional) field, enter:
User-agent: *\nDisallow: /\n
Click Create rule.
The origin website keeps serving its own files and its own robots.txt. Crawlers that request the origin domain follow that file, while the CDN rule applies only when the request uses the CDN custom domain.
Check the robots.txt response
Request /robots.txt on the CDN domain after the rule is in place. The response status is 200, and the body contains the disallow directive. The origin domain still serves its own robots.txt.
curl -i "http://<cdn-domain>/robots.txt"
User-agent: *
Disallow: /
Create a CDN rule for /robots.txt that returns a disallow directive. The exact ^/robots\.txt$ match limits the override to that path, so other responses stay as configured on the resource.
Send rule^/robots\.txt$ and ruleType0. Set options.force_return to status 200 and body User-agent: *\nDisallow: /\n, and leave time_interval out of the request.
Request /robots.txt on the CDN domain after the rule is in place. The response status is 200, and the body contains the disallow directive. The origin domain still serves its own robots.txt.
curl -i "http://<cdn-domain>/robots.txt"
User-agent: *
Disallow: /
Declare a CDN rule for /robots.txt with the Terraform provider v2. A request for that path on the CDN domain returns status 200 and Disallow: /, so compliant crawlers skip the CDN domain while the origin keeps its own robots.txt.
Block CDN crawling
The pattern ^/robots\.txt$ matches only /robots.txt on the CDN resource already declared in the configuration, so other CDN URLs keep the resource configuration.
Remove the rule block so the next terraform apply deletes the rule and leaves the CDN resource in place. /robots.txt then follows the resource configuration.
Request /robots.txt on the CDN domain after the rule is in place. The response status is 200, and the body contains the disallow directive. The origin domain still serves its own robots.txt.