↑ ↓ select, Enter open, Esc close

Change domain: replace the old domain in the database

Adjust the values, the command updates live
user@server
wp db export /var/www/vhosts/example.com/before-domain-change.sql --path=/var/www/vhosts/example.com/httpdocs && wp search-replace '//old.example.com' '//example.com' --all-tables --skip-columns=guid --path=/var/www/vhosts/example.com/httpdocs

Creates a database backup and then replaces every occurrence of the old domain with the new one, regardless of protocol. The leading // matches both http and https links and avoids partial matches inside other words. After the change, set up 301 redirects on the old domain so rankings and backlinks are preserved.

Note: The block editor and some page builders store URLs JSON-escaped as \/\/alt.example.com. For those cases, check a second run with escaped slashes using --dry-run.

Also searched as

  • wordpress change domain name
  • move wordpress to new domain
  • push staging to live wordpress
  • replace old url in database

Related one-liners

All in WP-CLI

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.