Backups and migrations

Change the domain or folder of a WordPress website

Reviewed on 7 min read wordpress migraciones

Changing the domain changes the address visitors use. Changing the folder changes where the files are stored and can leave that address untouched. Work out which operation you need before you start.

Create a recoverable backup of files and database and prepare the destination. If the public address changes, also plan the redirects following the guide on how to change a domain without losing SEO rankings

Change the WordPress domain

Before switching WordPress to a new domain, the first step is for that new domain to be set up in cPanel and, even more importantly, linked to the same path where your WordPress installation is.

For example, if WordPress is in public_html, you can add the new domain sharing the document root so it serves those same files.

If, on the other hand, it is in another path, untick the share option and enter the exact location of WordPress in the directory field.

This also applies if you want, for example, to change dominio.com to subdominio.dominio.com: in the same way, the key is that the subdomain is set up in cPanel and that it loads from the directory where WordPress is hosted.

Check that the new domain responds from the right directory and has a valid certificate before using HTTPS.

With the domain set up, log in to the WordPress dashboard as usual, go to Settings, then General, and change the "WordPress Address (URL)" and "Site Address (URL)" fields to reflect the new domain (do not forget https:// so they use the secure protocol).

The WordPress address must keep the subdirectory of its files if there is one; it does not have to be the same as the public address. If the fields are locked by constants in wp-config.php, follow the methods for changing the URL. These general instructions do not cover a Multisite network.

Save the changes and log in again using the new address.

Bulk replacement of the old domain

Although WordPress would already work on the new domain after this change, there may be addresses stored in the database that still refer to the old domain, mainly images, videos, internal links and theme or plugin options.

Before changing the database, create a recoverable backup. The replacement must be done with a tool that supports serialised data; an SQL REPLACE or editing the dump directly can break options, widgets and plugin settings.

For this we recommend the Better Search & Replace plugin.

Once it is installed, enter the full old URL in Search for, for example https://dominio.com, and the new one in Replace with, for example https://nuevodominio.com. Select the WordPress tables and first run Run as dry run to review how many changes will be made. Only after checking the result, repeat the operation with that option unticked. If there were also variants with http, www or a subdirectory, handle them separately and only once you have confirmed they appear in the installation.

Change the domain in Elementor and similar builders

In page builders such as Elementor, the bulk replacement and domain change may not be enough, and as a result you might see broken styles or images that do not load.

These builders have tools to fix these problems after a domain change. For example, in Elementor go from wp-admin to Elementor > Tools > Replace URL, enter the old and new domains in the form and check the result. You may need to regenerate the builder's files and clear the cache; this tool does not guarantee it will fix references from other plugins.

Change the WordPress path / location

Changing the path without changing the address

For organisational or any other reasons, you may want a website hosted in, for example, public_html/dominio.com to live in a new path, for example public_html/webs/dominio.com.

This change has no major implications for how WordPress works internally; you just need to bear in mind that the domain must point to public_html/webs/dominio.com.

Before moving it, create a backup of the files and database, check that the destination directory does not contain another application and schedule a maintenance window if the website receives orders, forms or changes.

The steps are as follows:

  • Move the WordPress directory to the new location. We recommend using the cPanel File Manager and waiting for it to finish. How long it takes depends on the content and the type of move.
  • Change the domain's path so it points to the new location.

Also move hidden files, keep your own .htaccess directives and then check permalinks, PHP version, scheduled tasks and any absolute path that mentions the old location. Changing the directory does not require replacing URLs if the public address stays the same.

Changing the path and the address

If, as well as changing the path, you also want the address to change, first prepare the final directory and then apply the address change steps. Check inner pages, images, the admin area and forms before retiring the old location. Keep redirects from the old URLs to their new equivalents, without sending every page to the home page.

You may also find useful

Something wrong or out of date? Tell us and we will review it.