How to redirect from one domain to another and save the path in the URL
how to set up a redirect from one domain to another and save the path in the URL

- In the “URL (required)” field, enter *domain1.com/*. The asterisk (*) acts as a wildcard to match any subdomain and path.
- Select the setting “Forwarding URL” from the drop-down menu.
- Choose the status code “301 - Permanent Redirect.”
- In the “Enter destination URL” field, enter https://domain2.app/$1. The $1 ensures that the path from the old URL is appended to the new URL.


- Add Rule name
- in "If..." section mark "All incoming requests"
- setup "Then..." section as shown on the screenshot
- in "Expression" field add concat("https://domain2.app",http.request.uri.path)


1. Add domain to Cloudflare account.
2. Navigate to the Page Rules Section and click on the "Create Page Rule" button

3. Configure the Page Rule:
- In the “URL (required)” field, enter *domain1.com/*. The asterisk (*) acts as a wildcard to match any subdomain and path.
- Select the setting “Forwarding URL” from the drop-down menu.
- Choose the status code “301 - Permanent Redirect.”
- In the “Enter destination URL” field, enter https://domain2.app/$1. The $1 ensures that the path from the old URL is appended to the new URL.

4. Click “Save and Deploy” to apply the rule.
5. Navigate to the Redirect Rules Section and click on the "Create Rule" button

6. Configure the Redirect Rule
- Add Rule name
- in "If..." section mark "All incoming requests"
- setup "Then..." section as shown on the screenshot
- in "Expression" field add concat("https://domain2.app",http.request.uri.path)

7. Click “Deploy” to apply the rule.
8. Navigate to the DNS -> Records Section and make sure you have Proxied enabled for domain1.com

9. Wait a while for the changes to take effect, after which you can check the redirect’s
Updated on: 09/08/2024
Thank you!