HostArmada Web Hosting Knowledge Base

Knowledge is power! Use that power and achieve total and unconditional control over the Web Hosting Services!

How can I change the domain name of my WordPress website?

Why would I change the domain of my WordPress website?

Knowing how to change your WordPress website’s domain name is a great asset, as it will allow you to rebrand your site or create clones where you can test various plugins, themes, or integrations. WordPress is a domain sensitive application, which means that when you install it on a specific domain, you cannot pick the files and place them within another domain name’s root directory and get it to work there. 

To use a different domain name, you will need to replace all the previous domain’s references within the database. There are a few ways you can do that, and inside this article, we will attempt to give you as much choice as possible so you can use the one you feel most comfortable. Without any further ado, let’s get started!

Change the WordPress domain using wp-config.php

This method is perhaps the easiest way of changing the URL of your WordPress website. After moving or copying your files under the new domain’s root folder, all you need to do is add the following lines in your wp-config.php file:

define('WP_HOME','http://domain.com');
define('WP_SITEURL','http://domain.com');

Of course, you need to replace the “domain.com” with the new URL you wish your WordPress to use. Here is an example:

define('WP_HOME','http://hostarmada.com');
define('WP_SITEURL','http://hostarmada.com');

There are a couple of ways you can edit this file, either using FTP, SSH, or the cPanel’s FileManager.

After adding those lines, save the files and access the new domain. You should see your WordPress using that website instead!

Change the WordPress URL using WP-CLI

For those of you who are not familiar with WP-CLI, you should check our knowledge base article here. In that article, you can also find many examples and commands to manage your WordPress through the command-line interface. The command you should be looking to use with WP-CLI is as follows:

wp search-replace “current-domain.com” “new-domain.com”

This command will go over all the tables in your database and replace your old domain with the new one. Please back up your database before executing the command above if something goes wrong, and you want to revert the changes. You can do that using WP-CLI when you type in the command:

wp db export

Executing the above will generate an SQL file of your database within the WordPress root directory. Alternatively, you can either export the database via SSH or do so using phpMyAdmin.

When you execute the command and complete its task, you should visit the new domain and see your WordPress site there! 

Change the WordPress domain name using the sed command

Sed is a powerful stream editor in Unix, allowing you to manipulate and format text in many ways as long as you are well acquainted with its functionality. We will be looking at one more way to perform a URL change for your WordPress website using the command line interface.

The first thing you need to do is expect your MySQL database. You can easily do that when you follow our export database via SSH knowledgebase article. After doing that, please use the command:

sed -i 's/current_url/new_url/g' <file>.sql

Here is an example:

sed -i 's/hostarmada.com/hostarmadatutorials.com/g' ha_wp18-2020-09-12-c47.sql

Sed will go through the SQL file, and wherever it finds a record of “hostarmada.com”, it will replace it with ‘hostarmadatutorials.com’.

Lastly, you will need to drop all your old database tables and re-import the newly replaced SQL to use the new domain. Dropping the tables can be done if you follow our phpMyAdmin tutorial, and you can import the new SQL using the MySQL command.

Change the WordPress domain using NotePad++(Windows) or NotePadQQ(Linux)

This method is pretty straightforward. First, you need to export your database locally. You can do that using phpMyAdmin. Afterward, open the file using either NotePad++ or NotePadQQ. Both editors allow you to select a file by pressing the “File” option on the top menu.

After opening the file, please press the “CTRL + F” sequence to open a window. This window has four tabs - select the 2nd one, which reads “Replace”. Beneath, you will see two text bars, the first holds the value you want to replace inside your SQL file, and the second one has the new value.

Enter your current domain name in the first text field and the new domain name in the second. Finally, hit the “Replace” button, located on the right side of the text fields. After a brief moment, all the old URL entries will be replaced with the new ones. Save the file by clicking on the “File” option on the top menu and then “Save As...” this will let you place it on your computer.

After you have the edited SQL file, it is now time to replace it on the server. Drop all the tables the database you just exported earlier, and import the new file you just changed. When done, accessing the website should start opening with the new domain name!

Conclusion

Being flexible regarding how you can change your WordPress website's domain name is excellent as you can perform this change under any circumstances. If you are hosting your WordPress under HostArmada and you do not feel confident enough to complete this change on your own, do not be alarmed! Our professional technical team is 24/7/365 at your disposal and will be happy to assist you. All you need to do is submit a support ticket through your Client Area!

Was this article useful and on point?

Find out more about HostArmada entire range of optimized Web Hosting Services and take action today on improving your website Loading Speed, Security, and overall Stability!