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
6 thoughts on “How To Change Your Domain Name”
I tried the first option but it didn’t work. I can’t even log in anymore. I’m aware you wrote in this article that this could happen if the new domain wasn’t configured correctly but I’m not sure what that means (or what I should’ve done to ensure it was in fact configured directly). Can you help me fix it??
Is that it? Just change a couple of settings?
What about the media library? Everything is linked absolutely so when the domain changes, they break.
Or internal links in our posts?
Eh? Eh?
Actually, I know the answer can be found on another of your posts, but I think you should probably have mentioned it here too.
Top blog btw, a great help
When I changed the wp-config.php I am no longer able to make changes to the URL under settings>general. any ideas why i am having that problem?
Hi Jeff
The wp-config overwrites the settings->general options that is why it is greyed out, if you remove the wpconfig settings, you can edit them from the dashboard please note, this will revert back to your previous domain so you may have issues.
To chaneg this you may need to edit teh database directly from wp-options table
I try the second one and it work, great
This is very helpful, i try it and it work also for me,
Comments are closed.