API: how to add multiple URL redirects (Page Rules)


I am struggling to add a Forwarding URL Page Rule via your API (with curl), What’s the correct syntax to use?

Ideally, I’d like to add multiple ones at the same time, not just one at once…

Any help or guidance greatly appreciated.


Yeah, they need to document that. You would add a forwarding URL via the API like so:

curl -X POST "https://api.cloudflare.com/client/v4/zones/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/pagerules" \
     -H "X-Auth-Email: [email protected]" \
     -H "X-Auth-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
     -H "Content-Type: application/json" \
     --data '{"targets": [{"target": "url","constraint":{"operator": "matches","value": "*yourdomain.com/*"}}],"actions": [{"id": "forwarding_url","value": {"url": "https://yourotherdomain.com","status_code": 302}}],"priority": 1,"status": "active"}

I’m not sure about doing multiple, but this should help get you started.

1 Like