Change URI path and Host header
Last updated May 5, 2026
This tutorial will instruct you how to modify both the URI path and the Host header of incoming requests using Transform Rules and Origin Rules.
Your website visitors will be routed from https://<YOUR_SOURCE_HOSTNAME>/uploads/* to https://<YOUR_TARGET_HOSTNAME>/*.
In this tutorial you will do the following:
- Create a URL rewrite to remove
/uploadsfrom the path. - Create an origin rule to modify the
Hostheader to desired hostname.
By following these steps, you can effectively manage both URI paths and Host headers to route traffic appropriately and optimize request handling.
1. Create a URL rewrite
- In the Cloudflare dashboard, go to the Rules Overview page. Go to Overview ↗
- Select Create rule > URL Rewrite Rule.
- Enter a descriptive name for the rule in Rule name.
- Under If incoming requests match, select Custom filter expression, select Edit expression, and enter the following expression:
Text in Expression Editor:
txt
raw.http.request.uri.path matches "^/uploads/.*"
- Under Set Rewrite parameters, select Path > Rewrite to, and select Dynamic.
- Define the action for your rewrite URL rule:
Text after Path > Rewrite to > Dynamic:
txt
regex_replace(raw.http.request.uri.path, "^/uploads/", "/")
The regex_replace() function replaces the /uploads/ part of the path with /, changing /uploads/example.jpg to /example.jpg.
7. Select Deploy.
2. Create an origin rule
Note
If you are routing traffic to an object storage bucket, use Cloud Connector instead of an origin rule.
- In the Cloudflare dashboard, go to the Rules Overview page. Go to Overview ↗
- Select Create rule > Origin Rule.
- Enter a descriptive name for the rule in Rule name.
- Under When incoming requests match, define the rule expression:
Text in Expression Editor:
txt
raw.http.request.uri.path matches "^/uploads/.*"
- Under Set origin parameters, select Host Header > Rewrite to.
- Configure the rule to modify the
Hostheader to desired hostname:
Text after Host Header > Rewrite to:
txt
example.com
This will set the Host header to example.com for matching requests. Make sure to replace example.com with your actual hostname.
7. (Optional) To route requests to a different origin (DNS target), use DNS override:
Text after DNS Record > Override to:
txt
example.com
This will route requests to the DNS target of example.com instead of your default DNS record.
8. Select Deploy.
Final remarks
After completing this tutorial, incoming traffic for https://<YOUR_SOURCE_HOSTNAME>/uploads/* will be routed to https://<YOUR_TARGET_HOSTNAME>/*.
Ensure the filters for the URL rewrite and the origin rule (or Cloud Connector rule) are precise to avoid unintended rule executions.
Remember that rules are evaluated in sequence, so Transform Rules (including URL rewrites) run before Origin Rules or Cloud Connector.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/rules/origin-rules/tutorials/change-uri-path-and-host-header/#page","headline":"Change URI path and Host header","description":"This tutorial shows you how to modify both the URI path and the Host header of incoming requests using Transform Rules and Origin Rules.","url":"https://developers.cloudflare.com/rules/origin-rules/tutorials/change-uri-path-and-host-header/","inLanguage":"en","image":"https://developers.cloudflare.com/rules/origin-rules/tutorials/change-uri-path-and-host-header/og.png?v=6dca63b34b634526","dateModified":"2026-05-05","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/"},"keywords":["Headers","URL rewrite"]}
description: This tutorial will instruct you how to configure an origin rule and a DNS record to point to a Pages deployment with a custom domain. title: Point to Pages with a custom domain image: https://developers.cloudflare.com/rules/origin-rules/tutorials/point-to-pages-with-custom-domain/og.png?v=8a6e6cfbfde0dc41
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt
Use this file to discover all available pages before exploring further.
Docs