Redirects with the CLI
owbase redirects: list, test, import, export and apply the redirect rules of a site, with the JSON file in your repository (redirects as code) and the exit codes for CI.
The owbase redirects group does on the command line what the console does in Redirects: it lists the rules of a site, tests URLs, imports an .htaccess, exports, runs the diagnostics, suggests destinations for 404s and changes the site settings. It is the same API as the console and the AI chat: the rules the CLI saves take effect at the edge immediately, with no new deployment.
The command that changes how you work is apply: the rules live in a JSON file in your repository, reviewed in pull requests like the rest of the code, and CI applies the file to the site (redirects as code).
CLI messages are in English, like the rest of the CLI; API errors arrive as the API returns them.
Credential, project and site
Section titled “Credential, project and site”- On your machine: the
owbase loginsession (Log in). - In CI and scripts: the
OWBASE_API_KEYvariable, which takes precedence over the session (CI with an API key). Reading, testing and exporting need thesites.readscope; saving (apply --yes,import --yes,suggest --apply-high --yes,configwith options) also needssites.writeandrules.read. - Project:
--project-id <id>or theprojectIdin the folder’sowbase.json. - Site:
--site <id>, in every command exceptlistwithout a site. The ID is inowbase sites list.
Every command accepts --json: the API result goes to stdout, and the text report goes to stderr.
owbase redirects list --site shopowbase redirects list --site shop --search blog --tag migrationowbase redirects listWith --site, the table shows the rules in the order they run: source → destination, status, type, whether it is enabled, tags and the ID; at the end, the site settings (www, trailing slash, _redirects file) and the plan usage. --search looks in the source, destination, description and tags; --tag shows only the rules with the tag.
Without --site, the list is the project’s: the sites that have rules, how many each one has and the plan usage.
Redirects as code
Section titled “Redirects as code”The file is what the JSON export produces, and it can live in the site’s repository:
owbase redirects export --site shop > redirects.json{ "config": { "www": "to-apex", "trailingSlash": "keep", "redirectsFile": true }, "rules": [ { "source": "/contact.php", "destination": "/contact", "statusCode": 301 }, { "type": "placeholder", "source": "/product/{id}", "destination": "/p/{id}", "statusCode": 301 } ]}Just the list of rules ([ {...}, {...} ]) also works. The fields of each rule are the API fields; whatever you leave out gets the default. The fields the server fills in ($id, siteId, createdBy, $createdAt, $updatedAt) can stay in the file: the CLI removes them before sending.
To apply:
owbase redirects apply redirects.json --site shopEach rule in the file becomes an upsert operation of a batch: the rule is matched by its source (type, path and domains; placeholder names do not count). A new rule is created, a changed rule is updated and an equal rule is left as it is, so applying the same file twice changes nothing.
Without --yes, nothing is saved. The command shows the plan: how many rules would be created, updated, kept and deleted, each change marked + (create), ~ (update), - (delete) and ! (problem), the problems of each rule, the plan usage after the change and the diagnostics of the set (loops, chains, rules that never run). To save:
owbase redirects apply redirects.json --site shop --yesThe batch is atomic: either everything goes in, or nothing does.
–prune
Section titled “–prune”owbase redirects apply redirects.json --site shop --prune --yesWith --prune, the rules of the site that are not in the file are deleted: the file becomes the complete list. Without it, apply only creates and updates. Check the plan without --yes the first time: everything created in the console that is not in the file shows up with -.
The settings in the file
Section titled “The settings in the file”If the file has config, apply also sets the site’s www, trailingSlash and redirectsFile, only where they differ (they show up under Site settings in the plan). Webhooks and codeFile depend on the project and are left out: use config.
on: pull_request: paths: [redirects.json] push: branches: [main] paths: [redirects.json]
jobs: redirects: runs-on: ubuntu-latest env: OWBASE_API_KEY: ${{ secrets.OWBASE_API_KEY }} OWBASE_PROJECT_ID: ${{ vars.OWBASE_PROJECT_ID }} steps: - uses: actions/checkout@v4 - run: npm i -g @owbase/cli@1 # On pull requests: only the plan. The step fails if a rule has a problem or goes over the plan. - run: owbase redirects apply redirects.json --site shop --prune # On main: save. - if: github.event_name == 'push' run: owbase redirects apply redirects.json --site shop --prune --yesThe step exits with code 1 when a rule has a problem or the result goes over the plan limit. In that case nothing is saved, and the report shows the limits and the upgrade address.
Import
Section titled “Import”owbase redirects import .htaccess --site shopConverts an .htaccess, nginx, _redirects (Netlify, Cloudflare Pages), CSV or JSON file into rules, like the console import. Without --yes it is only a preview: how many rules came out, how many would be created, updated and kept, the invalid ones with the problem, the lines left out grouped by code, with the reason and up to 5 examples, what became site settings and the rules over the plan.
| Option | What it does |
|---|---|
--format auto|htaccess|nginx|netlify|csv|json |
File format (default auto: Owbase recognizes it by the content). |
--mode merge|replace |
merge (default) joins with the site’s rules; replace leaves the site with only the file’s rules. |
--partial |
Over the plan limit: imports the first rules that fit, in file order. |
--yes |
Saves. |
Importing the same file again duplicates nothing (the same source updates the rule). If the file does not fit the plan and you do not pass --partial, the command exits with 1 and shows the upgrade address.
Export
Section titled “Export”owbase redirects export --site shop > redirects.jsonowbase redirects export --site shop --format htaccess -o .htaccess--format picks json (default), csv, htaccess, nginx or netlify (what each format carries). Without -o, it goes to stdout; with -o, the CLI does not overwrite an existing file without --yes. The JSON comes out indented, ready to version and for apply.
owbase redirects test /old https://shop.example.com/products/12 --site shopFollows each URL (or path) through the rules and the www and trailing slash settings of the site, without making a request to the site. The table shows the final URL, the status of the first response (site when no rule matches and the site itself answers), how many hops and the notes: chain (more than one hop: point straight to the final one), loop, external and no rule. --method tests another method (default GET). Up to 500 URLs at a time.
Exits with 1 if any URL falls into a loop.
Diagnostics
Section titled “Diagnostics”owbase redirects diagnose --site shopChecks the set: duplicate rules, rules that never run, loops, chains, destination equal to the source and expired schedules (details). Exits with 1 if there is an error; warnings do not fail.
404 suggestions
Section titled “404 suggestions”owbase redirects suggest --site shopowbase redirects suggest --site shop --days 30Lists the paths that returned 404, with the suggested destination (from the site’s sitemap, the visited pages and the rule destinations), the reason and the confidence: high, medium or low. Bot scan paths (/wp-login.php, /.env…) show up marked and without a suggestion: better leave them as 404. --days looks at the last days (default 7, up to the plan’s statistics days).
To create the high confidence suggestions as 301 rules:
owbase redirects suggest --site shop --apply-high # shows the planowbase redirects suggest --site shop --apply-high --yes # savesSite configuration
Section titled “Site configuration”owbase redirects config --site shopowbase redirects config --site shop --www to-apex --trailing-slash removeWithout options, shows the settings. With options, changes only what was passed:
| Option | Values |
|---|---|
--www |
off, to-apex (www.shop.example.com → shop.example.com) or to-www (the opposite) — how it works. |
--trailing-slash |
keep, add or remove the slash at the end of paths. |
--redirects-file |
true to keep applying the deployment’s _redirects file after the rules. |
--code-file |
true to read the rules from the deployment’s owbase.redirects.json file. |
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
Success (including the plan without --yes). |
1 |
Error, a rule with a problem or the plan limit in apply and suggest --apply-high, a file that does not fit the plan in import without --partial, a loop in test, an error in diagnose. |
See also
Section titled “See also”- Redirects: rule types, order, query, status, plan limits and the API.
- CI with an API key: the key in CI, without logging in.
- Sites with the CLI: deploying the site and
owbase.json.