2.13.1.8. Change site url in WordPress

Warning!

Before proceeding, it is strongly recommended create backups of the site and its database in order to be able to return the site to its original state if something suddenly goes wrong.

The article describes ways to change the site address only within WordPress itself. To rename a site on hosting (virtual host in the section "My sites" and the site directory on FTP), use instruction.

Important points:

  • If the old or new address contains symbols of the national alphabet (for example, Cyrillic), it must be converted to a panicode using converter.
  • Installed in the site settings redirect on HTTP / HTTPS must match the protocol in the new address. For example, if the site connected certificate and the redirect to HTTPS is set in the site settings, then the new address must start with https://... In the event of a protocol mismatch on the site, a cyclic redirect may occur between protocols http:// and https://.
  • Installed in the site settings redirect to the address from www or without www must match the new address. For example, if a redirect to an address from www is set in the site settings, then the new address must also be from www. In the event of a protocol mismatch on the site, a cyclic redirect may occur between the address with www and without www.

Warning!

If the names of the tables in the database do not start with the standard wp_, and with a different prefix, make the appropriate changes to the SQL queries.
  1. In the site config file takealook the name of the database to which it is connected.
  2. Openup database in phpMyAdmin.
  3. Execute the following three SQL queries:
    UPDATE wp_options SET option_value = REPLACE(option_value, 'http://old_domain.com', 'http://new_domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
    UPDATE wp_posts SET guid = REPLACE(guid, 'http://old_domain.com','http://new_domain.com');
    UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://old_domain.com', 'http://new_domain.com');
  4. To change the site address in the metadata, you should additionally execute one more request:
    UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://old_domain.com','http://new_domain.com');
  5. If the site uses comments, you should additionally execute two more requests:
    UPDATE wp_comments SET comment_content = REPLACE (comment_content, 'http://old_domain.com', 'http://new_domain.com');
    UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'http://old_domain.com', 'http://new_domain.com');
  6. Check the work of the site at the new address.
  1. Openup Adminpanel WordPress.
  2. Go to section "Settings → General".
  3. Enter a new address in the fields "WordPress address (URL)" and "Website address (URL)"... The address must start with a protocol http:// or https:// and there should not be a slash at the end /... An example of a valid address: http://example.com.
  4. Clickon "Save changes".
  5. Check the work of the site at the new address.

Warning!

The method should be used with caution if the database to which the site is connected is used simultaneously by several sites.
  1. Connect to hosting via SSH and install utility, if it has not been previously installed.
  2. Go to root directory site by running the command:
    cd ~/example.com/www

    In the team instead of example.com/www enter your details.

  3. Replace the site address in its database by running the command:
    wp search-replace 'old-address.com' 'new-address.com'

    In the team instead of old-address.com specify the old site address instead of new-address.com - new.
    As a result of executing the command, information will be displayed about where and how many replacements were made.

  4. Check the work of the site at the new address.

You can customize search with replacement more subtly (for example, only for certain tables or columns) using additional attributes described in documentation.

Content