Changing the domain everywhere on a WordPress website. Especially useful for Divi.

Jan 23, 2023 | Linux, Server administration, Technology | 0 comments


You have a WordPress website but the domain eventually changes for some reason.

You change the domain name in the general settings page but for some reason, you find tha tnot all your iamges are appearing.

You look in the source and easily notice that there are a lot of specific links to your old domain name. Primarily from Dibi.

This isn’t all that easy to fix. For some reason, Divi installs files with the FQDN of your website.

Also, you may have a lot of posts with the old domain name.

So here’s how you can fix all that:


You will need file system level access and database acccess on the command line to achieve this in the most efficient way. If you don’t have this, perhaps ask your hosting company. I’m sure they would love the extra work…

Alright. I assume you are logged into the MySQL server using the MySQL command line. I’m also assuing you have moved into the correct database using the “use” command.

Must I say it? Back everything up.

Okay. use these commands to replace the domain name in the options, posts and postmeta tables:

update wp_options set option_value = replace(option_value, ‘’, ‘’);

update wp_posts set post_content = replace(post_content, ‘’, ‘’);

update wp_postmeta set meta_value = replace(meta_value, ‘’, ‘’);

Okay. You’re done with the database. Exit out of that back to the command line.

Now update hte files in your website directory as follows: Again, you will need to update the path to your website here.

find /var/www/ ( -type d -name .git -prune ) -o -type f -print0 | xargs -0 sed -i ‘s/’


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.