In a previous post I wrote about migrating your WordPress hosting companies. Another common task I am asked to do it to change the domain name of a site but keep it on the existing hosting account.
Here is my how to on changing your WordPress site’s domain name
Why Change Your Domain Name
There are a number of reasons you may want to change your domain name, your company may change it’s name, your may be re-branding, you may have forgotten to renew your domain and lost it (you know who you are 🙂 ), you may be building the site with a temporary domain name but for whatever reason, it can be edited once your site has been built.
Before You Start
There are a couple of things you need to do before you start a domain name change.
Take a full backup – things can go wrong so you need a point in time to restore back to
Make sure the domain is pointing to your current installation, the test will be to attach to the new domain, you should be re-directed to the existing domain.
This is an intermediate to advanced how to.
There Are Three Ways To Do This
There are three ways to do this change, you can edit the general settings of your site, edit the wp-config.php file or directly change your database. They are ordered in ascending order of difficulty.
Edit General Settings
Scroll down to settings ->general and you will see two options with domain names WordPress Address and Blog Address.
To change the domain name, simply change the URLs in these two areas.
BE WARNED: As soon as you do this, your blogs address will be changed, if you do not have the new domain configured correctly, you will not be able to login.
Edit wp-config.php
The second way to change your domain name (and easiest to fix) is to set two new entries in your wp-config.php file.
Edi this file using the ftp client of your choosing and add the following two lines
define(‘WP_SITEURL’, ‘http://example.com/wordpress’);
define(‘WP_HOME’, ‘http://example.com/wordpress’);
These entries correspond to the two URLs from method one. Enter your new domain name and save the new wp-config.php.
When you attempt to access the old domain you will be re-directed to the new one. If you are having problems, simply remove these two lines and you will have access to your old domain.
Edit The Database Directly
This one is a bit more advanced, but if you are happy editing your WordPress database with tools like phpmyadmin then this is another way to change your domain name
Navigate to your options table, it may be called something like wp_options and find the two entries siteurl and home. Edit these database entries with your new URL sand save them to the database. Test as in the previous methods.
Save The Google Juice
If you have put a lot of time and effort into your content on the old domain name, there is agood chance you want to retain old links in Google. Fortunately WordPress does a good job of this, it will do a 301 redirect from your old domain name to your new one. A 301 redirect tells the search engines to change their index links to the new URL it is redirected to.
To test everything is working okay, type in site:yourdomain.com and click on a couple of links, if they go through and then redirect to your new URL everything is working great.
Search And Replace
Once you domain is working correctly, it is probably a good idea to search and replace your entire database to make sure any entries in blog posts etc are changed to the new domain.
I have already written about this in my WordPress Search And Replace post.
Wrap Up
It’s relatively painless to change your domain name, so don’t think you are stuck with a domain name you don’t really want.
Image by soschilds