If you decide to change your website’s address, you also need to change a number of settings in WordPress itself besides the changes in the domain in the hosting settings.
This step-by-step instruction describes actions you need to take to change the name of the website inside WordPress CMS.
Before you begin, remember to make a copy of your database just in case!
Let’s look at 2 variants:
The number of characters in the new domain coincides with the previous domain
- Go to phpMyAdmin and choose the database of your site.
- Press the SQL tab and complete the next query changing the old domain name to the new one. Pay attention though. At the end of the address, there should be no slash (/), and there should be HTTP protocol and not the HTTPS one:
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';
3. Go to the admin panel of your website to the Settings - Common.
4. In the WordPress Address and Blog Address fields, indicate the URL for the new domain and confirm the changes pressing the Refresh Options button.
5. If there is no possibility to do steps 3-4, then do the following queries, in turn, changing http://old_domain.com to the new website address. Pay attention that there is no slash (/) at the end of the address:
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');
The number of characters is different
We’ll need the WP-CLI package. The package will require the PHP 5.3.2+ version.
- Installing WP-CLI on Linux and OS X
$ curl -L https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > wp-cli.phar
The given command will load the wp-cli.phar file. To check the compatibility with the package, start the WP-CLI package with the --info parameter:
$ php wp-cli.phar --info
PHP binary: /usr/bin/php
PHP version: 5.4.24
WP-CLI root dir: phar://wp-cli.phar
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.14.1
suhosin must be turned off!
If the system is compatible, you can go ahead and copy the wp-cli.phar file into any directory which is located in the $PATH system variable. The copying is done so that WP-CLI can be called from any directory. The wp-cli.phar file itself must also be marked as executable.
$ chmod +x wp-cli.phar
For the VPS server, if you’ve logged under the root user:
$ mv wp-cli.phar /usr/bin/wp
For the shared/common Linux hosting:
$ mv wp-cli.phar /home/user/wp
$ vim ~/.bashrc
we add alias wp="/home/user/wp"
And log again via SSH.
After that, you can run wp --version from any directory.
2. Changing the domain name
Go to the root catalog of the website
We’ll ‘ask’ WP-CLI to change the old-domain.com to new-domain.com with the help of search-replace command
wp search-replace 'old-domain.ru' 'new-domain.com'
We see the following result:
Success: Made 238 replacements.