Serve images from custom domains
Last updated Apr 21, 2026 Image delivery is supported from all customer domains under the same Cloudflare account. To serve images through custom domains, an image URL should be adjusted to the following format:
https://example.com/cdn-cgi/imagedelivery/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT_NAME>
Example with a custom domain:
https://example.com/cdn-cgi/imagedelivery/ZWd9g1K7eljCn_KDTu_MWA/083eb7b2-5392-4565-b69e-aff66acddd00/public
In this example, <ACCOUNT_HASH>, <IMAGE_ID> and <VARIANT_NAME> are the same, but the hostname and prefix path is different:
example.com: Cloudflare proxied domain under the same account as the Cloudflare Images./cdn-cgi/imagedelivery: Path to triggercdn-cgiimage proxy.ZWd9g1K7eljCn_KDTu_MWA: The Images account hash. This can be found in the Cloudflare Images Dashboard.083eb7b2-5392-4565-b69e-aff66acddd00: The image ID.public: The variant name.
Custom paths
By default, Images are served from the /cdn-cgi/imagedelivery/ path. You can use Transform Rules to rewrite URLs and serve images from custom paths.
Basic version
Free and Pro plans support string matching rules (including wildcard operations) that do not require regular expressions.
This example lets you rewrite a request from example.com/images to example.com/cdn-cgi/imagedelivery/<ACCOUNT_HASH>.
To create a rule:
- In the Cloudflare dashboard, go to the Rules Overview page. Go to Overview ↗
- Next to URL Rewrite Rules, select Create rule.
- Under If incoming requests match, select Wildcard pattern and enter the following Request URL (update with your own domain):
txt
https://example.com/images/*
- Under Then rewrite the path and/or query > Path, enter the following values (using your account hash):
- Target path: [
/]images/* - Rewrite to: [
/]cdn-cgi/imagedelivery/<ACCOUNT_HASH>/${1} - Select Deploy when you are done.
Advanced version
Note
This feature requires a Business or Enterprise plan to enable regular expressions in Transform Rules. Refer to Cloudflare Transform Rules Availability for more information.
This example lets you rewrite a request from example.com/images/some-image-id/w100,h300 to example.com/cdn-cgi/imagedelivery/<ACCOUNT_HASH>/some-image-id/width=100,height=300 and assumes Flexible variants feature is turned on.
To create a rule:
- In the Cloudflare dashboard, go to the Rules Overview page. Go to Overview ↗
- Next to URL Rewrite Rules, select Create rule.
- Under If incoming requests match, select Custom filter expression and then select Edit expression.
- In the text field, enter
(http.request.uri.path matches "^/images/.*$"). - Under Path, select Rewrite to.
- Select Dynamic and enter the following in the text field.
regex_replace(
http.request.uri.path,
"^/images/(.*)\\?w([0-9]+)&h([0-9]+)$",
"/cdn-cgi/imagedelivery/<ACCOUNT_HASH>/${1}/width=${2},height=${3}"
)
Limitations
When using a custom domain, it is not possible to directly set up WAF rules that act on requests hitting the /cdn-cgi/imagedelivery/ path. If you need to set up WAF rules, you can use a Cloudflare Worker to access your images and a Route using your domain to execute the worker. For an example worker, refer to Serve private images using signed URL tokens.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/images/optimization/hosted-images/serve-from-custom-domains/#page","headline":"Serve images from custom domains","description":"Deliver Cloudflare Images through your own custom domain using the cdn-cgi image delivery path.","url":"https://developers.cloudflare.com/images/optimization/hosted-images/serve-from-custom-domains/","inLanguage":"en","image":"https://developers.cloudflare.com/images/optimization/hosted-images/serve-from-custom-domains/og.png?v=32909fb420d289db","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Restrict access to Cloudflare Images by generating signed URL tokens with expiration times. title: Serve private images image: https://developers.cloudflare.com/images/optimization/hosted-images/serve-private-images/og.png?v=7299ee84ae1a2d1a
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/images/llms.txt
Use this file to discover all available pages before exploring further.
Docs