Skip to content
Home » How to Change Your WordPress Site URL

How to Change Your WordPress Site URL

how-to-change-your-wordpress-site-url

Having decided to change the site address, you should remember that in addition to changing the domain in the hosting settings, you need to change a few settings in WordPress itself. If this is not done, the site or part of its functionality will stop working.

When transferring a site from a local server to a working one, it is also important not to forget about changing the domain if the addresses are different. Our article will help you figure out what’s wrong and correctly change the site address so that it can work properly.

Why WordPress doesn’t work with a new domain

To build all links inside WordPress, several settings are used that store the site address (its domain). They are set once at the time of installing WordPress, after which they are stored in the wp_optionsdatabase table and require manual updating if you decide to change the site address.

Things to remember before changing a domain

In addition to updating the domain settings on the General settings page (Settings → General), it is worth remembering some more things that take place.

  1. Links in articles and pages.
  2. Links in the settings of themes and plugins.
  3. Pictures in articles, pages, and other places on the site.
  4. Column guidin a table wp_posts, etc.

Sometimes a domain can be stored as a serialized value within a database. In practice, this happens if a whole array of values ​​is written to one “cell” of the database. And if the number of characters in the new and old domain differs, then most of the methods with a simple replacement through the search, which the Internet “tells about,” will give a misfire.

In the illustration below, “cell” 1 stores a regular value, and 225 stores a serialized value, where, in addition to the value itself, its size is also indicated.

Fortunately, the WP-CLI utility takes care of all this, which can search and replace strings wherever and in what format they are stored in the database. We will touch on working with it later in this article, but first things first.

“Difficulties” with Cyrillic .рф domains

The Domain Name System (DNS) is designed so that site addresses can only contain English letters, numbers, and the “-” symbol. All other characters must be written as combinations of these valid characters. For view domains, мой-сайт.рфthis means that the domain entry in the WordPress settings must be in Punycode format.

You can automatically convert a domain .рфfrom Cyrillic to Punycode at mothereff.in/punycode .

Change site domain using WP-CLI

The WP-CLI utility is a universal tool, among the many features of which there is a competent search with the replacement of any strings within the database. We assume that WP-CLI is already installed on the hosting. If this is not the case, you can ask the provider’s support to install the utility or perform the domain change procedure on your local server.

Be sure to back up your database before starting, just in case.

So, to change the domain of the site, we connect via SSH to the server and use the command cd to go to the folder with our site.

ssh user666@old-domain.ru -p 7777
# By default, when connecting, port 22 is used,
# but on many hostings, the port is specially changed
# to another, for example, in the example above, this is port 7777.
# Enter password ?
cd /home/user666/old-domain.ru/public_html/
# The path to the site may be different

Use the search-replace”ask” command to replace WP-CLI old-domain with .new-domain.com

wp search-replace 'old-domain.ru' 'new-domain.com'
new - domain . com '

A command like this will only replace the old domain with tables that are relevant to the current WordPress installation. After execution, a table with some statistics will be displayed.new-domain.com.

Using additional attributes, you can specify specific tables and columns in tables where you want to replace them. Be careful if you have multiple site tables in the same database. Also in WP-CLI, there is a command wp option update to update individual options.

Change website domain using PHP script

In case, for some reason, WP-CLI is not available, you can use a PHP script from Interconnect IT from Liverpool. To use it, you only need FTP access. Like WP-CLI, the script takes care of all data formats and won’t break serialized values.

Again I note that just in case it is better to make a backup copy of the database before starting.

1. So, download the ZIP archive of the latest version from Github.

2. Let’s go to the root folder of the site on the server via FTP. Right in the root of the WordPress installation, create a “secret” folder with any name. Be sure to make the name as complex as possible with mixed-case letters, numbers, and the “-“ symbol. This name is necessary so that no one except you can find it and use the script – it does not require authorization and any user who visits the page will be able to interact with your database.

3. Unpack the contents of the archive downloaded in the first step and upload it to a “secret” directory.

4. Let’s open the script we just downloaded. To do this, open the page in the browser. As you might guess, “replacer-x36D891EHY-“ is the name of the secret directory.example.org/replacer-x36D891EHY-/

5. On the page that opens, in the “replace” field, you must specify your old domain (for example, old-domain.ru), and in the “with” field, the new domain (for example, ).new-domain.com

Uncheck “use regex“. The data in the “database” section should automatically populate when the page is opened. In the “tables” section, select “all tables”.

6. The “actions” section contains several action buttons. We are interested in the “live run” button. By clicking on it, a dialog box will open in which you must confirm the launch by clicking the “OK” button.

7. The domain search and replacement process will begin. Don’t close the page! During execution, the results of the operation will appear.

8. After a successful replacement, you must delete the “secret” directory with all the contents. This can be done through an FTP client. Through the “delete me” button at the bottom of the page, the script may not be deleted, so it is safer to do this through an FTP client.

Also see: Options performance in WordPress

Instead of a conclusion

We have looked at the two most correct ways to change the domain of a WordPress site. There are other ways to do this described on the Internet, but most of them do not take into account many of the intricacies of storing data in databases.

The tools described in the article for replacing the site address can also be used for other purposes when you need to perform a search with the replacement of any strings within the database. If you have any questions while changing the site address, write a comment and we will try to help you.

Leave a Reply