Step 1 – Backup your database!

Step 2 – Install Better Search Replace Plugin

You can do this from your Plugins menu. The plugin is also available in the WordPress repository here.

Step 3 – Tell WordPress about the new URL

You can do this under Settings > General. You will need to set the Home URL and the Site URL which will usually be the same thing.

This will automatically update any internal links within menus, locations of featured images etc, but you will still need to replace the url where it is used within inline images or other content areas

Step 4 – Search and Replace your database

This bit is destructive – proceed with caution!

Open the Search and Replace plugin page from the Tools menu

Search for your old URL and replace with your new URL

Select the tables to search. Start with wp_options, wp_posts and wp_postmeta

You may wish to test with a dry run initially, if so leave the Dry run box ticked