WordPress Move Domain Names

GeekThis remains completely ad-free with zero trackers for your convenience and privacy. If you would like to support the site, please consider giving a small contribution at Buy Me a Coffee.

Switching domain names when using WordPress involves a few steps you may not think are required. Since WordPress saves the domain name permanently to the database, we have to modify the database along with a few configuration files to move WordPress to a different name. Below is a step by step guide to move your WordPress installation from your old domain name to your shiny new domain name.

This tutorial requires a few key pieces of software. You can either use the programs I list off or use your favorite alternative for each of these programs. Also, with any tutorial in which you have to edit files, creating a backup of everything is highly suggested

  • FTP Client: FileZilla, WinSCP, SmartFTP, or one of the many others that exist.
  • Database Backup Method: PHPMyAdmin, MySQLDump, WordPress Plugin, or use an equivalent method to MySQLDump that your specific database uses.
  • Notepad: Any notepad will work (that doesn’t add formatting) that is able to replace text. I suggest Notepad++, Sublime Text, Geany or any other programmer notepad.

Backup the Database

Download the full database in SQL format. It’s going to be a very large file depending on how many posts, images, and comments your site has. Downloading your database, or better known as backing up your data is a simple task, but there are many different ways to go about it. The best known way is using PHPMyAdmin, which will be explained below.

  1. Open up PHPMyAdmin through cPanel or your equivalent of a web server manager, or directly through your web browser.
  2. Find the Database which WordPress is installed to. Some table names for WordPress will be *_users, *_postmeta, *_posts, *_terms and others. The asterisk acts as a wildcard, and is usually wp_ unless changed during your installation.
  3. In the controls for this Database, you should see “Structure”, “SQL”, “Search”, a few others, including the one we need of “Export”.
  4. Using the Quick backup option with the file format SQL should set everything you need. If you are like me though, taking a look behind the scenes of Custom is more of the way to go.

Modify the Database

Open up your newly downloaded database file (SQL File) and open up the search and replace tool. We have to replace all instances of our old domain with the new domain. It’s very important that you enter the full website address, including the protocol (http / https).

  1. Open the Find & Replace tool. Usually found under the menu Search or using the hotkey Ctrl + H.
  2. For “Find what”, you will want to enter your old domain name, such as “http://www.old-name.tld” but without the quotes.
  3. Now click on “Count” to find out how many instances that url appears in the file. If you don’t see the option “Count”, open up the normal Find tool and search for that domain again, including the protocol and tld. You should have at least the number of posts you have in links. For a site I have of 50 posts, I have over 100 links found. If for some reason your search is only showing up a few results, make sure you entered the correct sub domain also.
  4. Enter in the “Replace with” field the new domain name, including protocol also, such as “http://www.new-domain.tld”, and replace all and save your file.

We only have a few steps left. The task now is to move your WordPress files to your new domain folder. If you are using the same host, this is incredibly easy to do. If you are switching hosts, it’s a little bit more difficult and requires us to edit another file.

Switching Domains on the Same Host

  1. Rename your current WordPress directory, such as public_html, www, old-domain.tld or any variation to where your new domain points to. The folder is most likely the new domain name, such as new-domain.tld.
  2. Create a new folder with the name of the folder you just overwrite, such as public_html or www.
  3. Your old site should just show a empty page or a default message from your hosting company. Your new domain should probably show a page that has error messages since we are not yet finished, or the new domain may just be a white page if error messages are turned off. Skip passed to the header about Importing New Database.

Switch Domains and Hosts

  1. Save your WordPress files onto your computer from your FTP Client.
  2. Upload all of these files to your new host into the new domain’s root directory. When you visit your new domain, you should see some sort of error messages most likely since we have yet to create a database. If it’s just a white screen, that’s alright also, since error messages may be turned off.
  3. Create a new database on your new webhost. This is different for all web hosts, so you will have to look at their how-to guide, contact them, or just mess about in the administration panel for a bit.
  4. Open up the WordPress directory we backed up, and open the file wp-config.php in the root of the directory.
  5. The first 5 lines which are not comments or comment blocks we have to edit. These lines define your database information, which we have changed. Replace the values for DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Don’t replace that text I listed, but the text right to it.
  6. Upload your wp-config.php file to your new web host, and replace the old one.

Importing your New Database

We are finally at the final step to get our new domain running. We have to now import our modified database.

  1. In your old database, if you are using the same hosting account, drop all the tables for WordPress (backup first). You should still have the database you were using for your previous WordPress installation, but just have it empty. If you are switching hosts along with domain names, you don’t have to delete anything from a database since you created a new one.
  2. In the newly cleared or created database, go to “Import” and import the SQL file we replaced our domain names in.
  3. Navigate to your new domain name, and you should see your website fully functioning. While on your site, visit links through your site and make sure you stay on your new domain name, also check the images source.

There is one last thing, that is optional, but highly recommended so your old visitors and search engines can find your site. We have to create a htaccess file which redirects users to the new domain name.

Create a file named “.htaccess”. There is no file extension, and the filename must start with a period. Enter the following content into the file and save it and upload it to your old domains folder, such as public_html or old-domain.tld. You will have to change the last two lines to reference your new domain name.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !new-domain.tld$ [NC]
RewriteRule ^(.*)$ http://new-domain.tld/$1 [L,R=301]

Related Posts

Custom Style RSS Feed

Customize the look and feel of your WordPress RSS feed by adding a stylesheet to your RSS XML feed.

Favicons Inside of WordPress

Learn how to add custom favicons and browser icons to your WordPress site.

Repair WordPress White Screen

Watch our video to learn how to fix your WordPress site when it's showing only a white page.

Installing WordPress Plugins

Watch our video and learn how to install custom plugins to WordPress to add additional features to your site.