How to Clone Cloudflare Configuration (English)
Managing multiple websites can be tedious when you have to manually configure DNS records, Page Rules, and Security Settings for every new domain. This guide demonstrates how to use the Cloudflare API to clone an entire configuration from a source domain to a target domain in seconds.
1. API Token Preparation
To automate the process, you need a User API Token with the following permissions:
- Go to: Cloudflare API Tokens -> Create Token.
- Permissions:
Account-Account Settings-ReadZone-Zone Settings-EditZone-DNS-EditZone-Page Rules-EditZone-SSL and Certificates-EditZone-Firewall Services-EditZone-Zone WAF-EditZone-Zone-Edit
- Zone Resources: Select All zones from an account (allows reading from source and writing to target).
2. The Workflow (Hybrid Script)
We use a “hybrid” Python script that supports both direct file editing (for humans) and Command Line Arguments (CLI) for Bots/Automation.
Source Code
Download the sample script here: cloudflare_clone_script.py
Usage
Method 1: For Humans (Manual)
- Open the script file.
- Edit the
DEFAULT_CONFIGsection at the top. - Fill in your Token and IDs.
- Run:
python cloudflare_clone_script.py
Method 2: For Bots/Automation (CLI) No file editing needed. Just pass arguments:
python cloudflare_clone_script.py \
--token "YOUR_TOKEN" \
--source-id "SOURCE_ZONE_ID" \
--dest-id "DEST_ZONE_ID" \
--source-domain "old-site.com" \
--dest-domain "new-site.com" \
--ip "1.2.3.4"
What The Script Does
Step 1: Clone DNS Records
The script reads essential records from the source and recreates them on the target:
- A Records: Point
@andwwwto the destination VPS IP (e.g.,your_vps_ip). - MX/TXT Records: Automatically setup Email configurations (e.g., LarkSuite, Google Workspace).
Step 2: Clone Page Rules
This is the most valuable part. The script will:
- Fetch Page Rules from the source domain.
- Replace the old domain string with the new one.
- Push the modified rules to the new domain.
Benefit: Preserves critical security rules like protecting
wp-adminor caching static files without manual reentry.
Step 3: Sync Zone Settings
Apply standard security settings:
- SSL/TLS: Flexible/Full.
- Always Use HTTPS: ON.
- Min TLS Version: 1.0 (or 1.2 for higher security).
- Security Level: Medium.
3. The Result
With a single script execution, the new domain sensakai.com is ready to serve traffic with:
✅ Correct DNS records pointing to the new VPS.
✅ Security Page Rules identical to the source site.
✅ HTTPS enabled automatically.
This solution saves hours of manual work and ensures consistency across your entire web system.