Backups and migrations

Change the WordPress domain or URL

Reviewed on 6 min read wordpress migraciones

When you change domain, move WordPress to a subdirectory or publish a copy, you may need to change its main URL. The method depends on the access you still have to the installation.

Before using any of these methods, keep a recoverable backup of files and database, check that the new domain points to the right directory and that its HTTPS certificate works. This guide covers a single installation; a Multisite network needs a specific procedure.

Below are three main methods for changing the WordPress URL, ordered from the simplest to the most technical.

Method 1: From the WordPress dashboard (wp-admin)

This is the simplest and recommended way when you have access to the WordPress dashboard.

  1. Log in to the WordPress dashboard (wp-admin)

  2. Go to Settings → General

  3. Change the fields:

    • WordPress Address (URL): the URL where the main WordPress files are
    • Site Address (URL): the URL visitors will see
  4. Click Save Changes

Important: Make sure both URLs are correct before saving, as a mistake could lock you out of the dashboard.

Method 2: Editing the wp-config.php file

Use this method when you have no access to the dashboard because of the URL change.

  1. Connect to your account via FTP or with the file manager
  2. Find and edit the wp-config.php file in the root of your WordPress installation
  3. If these constants already exist, change their values without duplicating them. If they do not exist, add the following lines before the comment "That's all, stop editing!", ahead of WordPress being loaded:
define('WP_HOME','https://tudominio.com');
define('WP_SITEURL','https://tudominio.com');

Replace tudominio.com with your real domain. WP_SITEURL must point to where the WordPress files are and WP_HOME to the website's public address; they will only be the same if both locations match.

These constants take precedence over home and siteurl in the database, but do not change their values. While they are defined, you also cannot edit the addresses from Settings > General. If you use them to regain access, update the stored options afterwards and remove the constants so the old URL does not come back.

Method 3: Editing the database directly (phpMyAdmin)

This method is more technical and should be used with care.

Editing process:

  1. Open phpMyAdmin from your hosting control panel

  2. Select your WordPress database

  3. Check DB_NAME and $table_prefix in wp-config.php to identify the right database and table. Find wp_options or the equivalent table with that prefix

  4. Find the following rows and edit their values in the option_value column:

    • home: change it to the new URL (example: https://tudominio.com)
    • siteurl: change it to the new URL (example: https://tudominio.com)
  5. Save the changes

After changing the main URL using any of the methods above, it is strongly recommended to update all the internal references WordPress stores in the database, as many items (images, internal links, widgets, etc.) may still point to the old URL.

Before doing so, create a recoverable backup of the database. Do not run a direct SQL replace or edit the dump as text: WordPress and its plugins store serialised data that would be damaged if the length of a URL changes.

Why is this extra step needed?

Even after changing the main WordPress URL, the database may contain thousands of references to the old URL in:

  • Post and page content
  • Image and media file URLs
  • Widget and menu settings
  • Theme and plugin options

Using Better Search & Replace

  1. Install the Better Search & Replace plugin from the official WordPress repository

  2. Go to Tools → Better Search Replace

  3. Fill in the fields:

    • Search for: the full old URL (example: https://dominioviejo.com)
    • Replace with: the full new URL (example: https://dominionuevo.com)
    • Select tables: select the installation's tables you are going to change
    • Run as dry run?: leave it ticked on the first run to review the number of changes
  4. Check the result of the dry run and, only if it is correct, repeat the operation with that option unticked.

Do not replace just the bare domain: you could change email addresses or other values that are not URLs. Handle the http, https, www or subdirectory variants you have confirmed in the database separately.

Using WP-CLI (advanced method)

If you have access to WP-CLI, run the command from the right installation's folder, or give its path with --path. You can simulate the replacement like this:

wp search-replace 'https://dominioviejo.com' 'https://dominionuevo.com' --skip-columns=guid --dry-run

By default, WP-CLI processes the tables registered for that installation; check whether any plugin uses other tables before widening the scope. Do not add every table in the database indiscriminately if several applications share it.

First run it with --dry-run to simulate, then without that option to apply the changes. WP-CLI respects serialised data; --skip-columns=guid avoids altering the posts' permanent identifiers.

You may also find useful

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