2.13.1.8. Change site url in WordPress
Warning!
Before taking any action, be sure create a backup site files and its database in order to be able to return the site to its original state if something suddenly goes wrong.This article describes how to change the site address only within WordPress itself. To rename a site in a section «My sites» and 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 protocolshttp://
andhttps://
. - Installed in the site settings redirect to the address from
www
or withoutwww
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 withwww
and withoutwww
.
- Clickon "Change address".
- Enter a new website address and click «Change site url".
The system takes the name of the used database from the site configuration file and changes the old address in it to the new one.
Warning!
If the names of the tables in the database do not start with the standardwp_
, and with a different prefix, make the appropriate changes to the SQL queries.
- In the site config file takealook the name of the database to which it is connected.
- Openup database in phpMyAdmin.
- 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');
- 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');
- 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');
- Check the work of the site at the new address.
- Openup Adminpanel WordPress.
- Go to section "Settings → General".
- Enter a new address in the fields "WordPress Address (URL)" and "Site address (URL)". The address must start with a protocol
http://
orhttps://
and there should not be a slash at the end/
. An example of a valid address:http://example.com
. - Clickon "Save changes".
- 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.- Go to root directory site by running the command:
cd ~/example.com/www
In the team instead of
example.com/www
enter your details. - 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 ofnew-address.com
- new.
As a result of executing the command, information will be displayed about where and how many replacements were made. - 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.