cf-redirects is a small Go CLI that discovers Cloudflare bulk redirect lists across the accounts available to your API token and prints each redirect as:
- source URL
- target URL
- status
- parameters
It supports tsv output by default, plus csv, table, and json.
Create a Cloudflare API token with at least:
Account Filter Lists Read
The CLI uses the Cloudflare v4 API to:
- List accessible accounts
- Find redirect lists in each account
- Fetch the redirect items from those lists
If you are setting up Bulk Redirects in Cloudflare, the easy-to-forget DNS details are:
- The hostname being redirected must be proxied by Cloudflare.
- For a redirect-only hostname with no origin behind it, use a proxied
Arecord pointing to192.0.2.1. - If you also redirect
www, create a proxied record forwwwtoo.
Typical DNS records look like:
Type Name IPv4 Proxy
A @ 192.0.2.1 Proxied
A www 192.0.2.1 Proxied
Then create:
- A Bulk Redirect List containing the source and target URLs
- A Bulk Redirect Rule that enables that list
Cloudflare docs for this setup:
- Redirect one domain to another: https://developers.cloudflare.com/fundamentals/setup/manage-domains/redirect-domain/
- Create Bulk Redirects in the dashboard: https://developers.cloudflare.com/rules/url-forwarding/bulk-redirects/create-dashboard/
cf-redirects looks for a token in this order:
CLOUDFLARE_API_TOKENCF_API_TOKEN.env
Environment variables take precedence over values in .env.
CLOUDFLARE_ACCOUNT_ID is optional. Use it when:
- your token cannot enumerate accessible accounts
- you want to scope the CLI to one account by default
export CLOUDFLARE_API_TOKEN=your_token_here
export CLOUDFLARE_ACCOUNT_ID=your_account_id_here # optionalCreate a .env file in the repo root:
CLOUDFLARE_API_TOKEN=your_token_here
CLOUDFLARE_ACCOUNT_ID=your_account_id_hereYou can copy the example file:
cp .env.example .envgo run ./cmd/cf-redirects listPrint the binary version:
go run ./cmd/cf-redirects version
go run ./cmd/cf-redirects --versionDefault output is tab-separated, one redirect per line:
example.com/old https://example.com/new 301 preserve_query_string,subpath_matching,preserve_path_suffix
Pretty table output:
go run ./cmd/cf-redirects list --format tableJSON output:
go run ./cmd/cf-redirects list --format jsonCSV output with headers:
go run ./cmd/cf-redirects list --format csv --headerFilter to a specific account or list:
go run ./cmd/cf-redirects list --account-id <account_id>
go run ./cmd/cf-redirects list --list-id <list_id>Show account and list IDs in human output:
go run ./cmd/cf-redirects list --format table --show-ids
go run ./cmd/cf-redirects list --show-idsUse a custom env file path:
go run ./cmd/cf-redirects list --env-file .env.localDefault output is TSV and prints exactly four columns per line:
- source URL
- target URL
- status
- parameters
With --show-ids, TSV output prepends:
- account ID
- list ID
Add --header if you want a header row for spreadsheet import.
Use --format csv for comma-separated output with proper CSV quoting. Add --header when you want column names in the first row.
--format table prints those same fields in a formatted table with headers. With --show-ids, it also includes account and list IDs.
--format json prints structured records and includes extra metadata:
account_idaccount_namelist_idlist_name- redirect fields
- a derived
parametersarray
Legacy shorthands still work:
--jsonmaps to--format json--tablemaps to--format table
make fmt
make test
make buildLocal builds default to version dev. To stamp a specific version into the binary:
make build VERSION=v0.1.0
./cf-redirects versionGitHub Actions builds release archives for:
- Linux
amd64andarm64 - macOS
amd64andarm64 - Windows
amd64andarm64
On every push to main, pull request, or manual workflow run, the workflow produces downloadable build artifacts in GitHub Actions.
To publish executables as a GitHub Release, push a version tag:
git tag v0.1.0
git push origin v0.1.0That tag creates release archives such as:
cf-redirects_v0.1.0_linux_amd64.tar.gzcf-redirects_v0.1.0_darwin_arm64.tar.gzcf-redirects_v0.1.0_windows_amd64.zip