WP CLI

Redirection provides a limited set of WP CLI commands:

  • wp redirection import – import from a file
  • wp redirection export – export to a file
  • wp redirection database – install or upgrade a site
  • wp redirection setting – set or get a Redirection setting
  • wp redirection plugin – import from other plugins

Note that all actions are available for single or multi site using the appropriate WP CLI parameter.

Importing

You can import CSV, JSON, or .htaccess files using WP CLI. The format is:

wp redirection import <filename> --format=<format>

Where <format> is one of:

  • csv
  • apache
  • json

Exporting

You can export to CSV, JSON, .htaccess, or Nginx format files using WP CLI. The format is:

wp redirection export <module> <filename> --format=<format>

Where --format is one of:

  • csv
  • apache
  • json
  • nginx

And <module> is one of:

  • all – all Redirection modules
  • wordpress
  • apache
  • nginx

Database

You can perform Redirection database actions using WP CLI. The format is:

wp redirection database <action>

Where <action> is one of:

  • install – Install the Redirection database tables
  • remove – Remove the Redirection database tables
  • upgrade – Upgrade the Redirection database tables to the latest version

Settings

You can get or set Redirection options using WP CLI. The format is:

wp redirection setting <name>

Where <name> is the setting name.

You can update a setting with:

wp redirection setting <name> --set=[value]

The value should be in JSON format if it is anything other than a string or number.

Note that the value will be validated according to the setting.

Plugin Import

You can import redirects from any supported plugin. The format is:

wp redirection plugin <name> [--group=ID]

Where <name> is the plugin name:

  • wp-simple-redirect
  • seo-redirection
  • safe-redirect-manager
  • wordpress-old-slugs
  • rank-math
  • quick-redirects

An optional group ID can be supplied, otherwise the redirects will be imported into the first group.