Prevent SiteGround staging copy from prepending www

If, on SiteGround, you make a staging copy of a website that prepends www, the staging copy will try to do the same, so you end up with something like This creates a few problems—most notably with the automatically created Let's Encrypt certificate, which won't work since the subdomain doesn't match.

The solution is simple, but not obvious: In the staging copy's database, remove www from all URLs.

To do this quickly, ssh into your server, cd to the staging copy's directory and execute this command, substituting with your domain:

wp search-replace '' '' --precise --all-tables --recurse-objects --dry-run

After you see that the dry run works as expected, run the command again without the --dry-run argument.

Of course, after you push the staging copy to live, you'll need to do the reverse search-replace on the live site.