To change URI Path and Host Header on incoming requests simultaneously:

1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and select your account and domain.

2. Create a URL rewrite:

   * Go to **Rules** > **Overview**.
   * Select **Create rule** > **URL Rewrite Rule**.
   * Configure the rule to modify the path. For instance, to remove `/uploads` from the path:

Text in **Expression Editor**:

```txt
raw.http.request.uri.path matches "^/uploads/.*"
```

Text after **Path** > **Rewrite to** > *Dynamic*:

```txt
regex_replace(raw.http.request.uri.path, "^/uploads/", "/")
```

The `regex_replace()` [function](https://developers.cloudflare.com/ruleset-engine/rules-language/functions/#regex_replace) replaces the `/uploads/` part of the path with `/`, changing `/uploads/example.jpg` to `/example.jpg`.

1. Create an **Origin Rule**:

   * If routing traffic to an object storage bucket, use [Cloud Connector](https://developers.cloudflare.com/rules/cloud-connector/). Otherwise, go to **Rules** > **Overview**.
   * Select **Create rule** > **Origin Rule**, and then select **Host Header** > **Rewrite to**.
   * Configure the rule to modify the Host header to desired hostname:

Text in **Expression Editor**:

```txt
raw.http.request.uri.path matches "^/uploads/.*"
```

Text after **Host Header** > **Rewrite to**:

```txt
example.com
```

This will set [the Host header](https://developers.cloudflare.com/rules/origin-rules/features/#host-header) to `example.com` for matching requests.

**Optional:** To route requests to a different origin (DNS target), use [DNS override](https://developers.cloudflare.com/rules/origin-rules/features/#dns-record):

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](https://developers.cloudflare.com/dns/manage-dns-records/how-to/create-dns-records/).

This setup routes traffic from `https://<YOUR_SOURCE_HOSTNAME>/uploads/*` to `https://<YOUR_TARGET_HOSTNAME>/*`. Ensure the filters for [Transform Rules](https://developers.cloudflare.com/rules/transform/) and [Origin Rules](https://developers.cloudflare.com/rules/origin-rules/) (or [Cloud Connector](https://developers.cloudflare.com/rules/cloud-connector/)) are precise to avoid unintended rule executions.

Remember that rules are evaluated [in sequence](https://developers.cloudflare.com/ruleset-engine/reference/phases-list/), so Transform Rules run before Origin Rules or Cloud Connector.

Make sure to replace `example.com` with your actual hostname and adjust the example paths according to your setup. By following these steps, you can effectively manage both URI paths and Host headers to route traffic appropriately and optimize request handling.
