Hello and thanks for reading a second WP migration tutorial on our blog.
In the first one called WP Migration 101, we talked about what WP migration is, what are the reasons for WP migration as well the 3 different types of migration.
Among the other two(hosting to hosting and local to hosting), we also mentioned “Changing WordPress domain name“, which is exactly what you will learn from this second tutorial ๐
Why would you ever change the domain name of your WordPress website?
There are quite a few reasons why one may decide on such a step, but here are the most usual ones:
#1- Changing from dev or localhost URL to the live domain.
Whenever you make a duplicate of your site for any purpose, you can’t host it on exactly the same URL(as the original site is already sitting there).
When people want to test more major changes on their WP site, they usually either set it up on localhost(http://localhost), a dev subdomain(for example http://dev.yourdomain.com), or in a subfolder(http://yourdomain.com/dev).
Whatever the dev URL, once done, the site should be migrated back to the live domain.
#2- WordPress site Rebranding
Rebranding is the second most common reason why people decide to change the domain of their WordPress site.
If you decide to change your company name, you will most likely want to change your domain name as well.
So, if your company changed its name from “California Sun” to “California Beaches”, you’ll probably want to change your domain name “californiasun.com” to “californiabeaches.com”.
When you already have a domain that was established for a while and want to change it, special attention should be paid to SEO. We will cover this topic in more detail later, but for now, remember that failing to 301 redirect your old domain to a new one means you’ll lose any traffic established on the old domain.
This is how we change the domain name of your website
#1- Once you buy the new domain name, you need to connect it with your hosting account
Depending on whether your hosting and registrar are the same company or not, this may already be taken care of for you.
But if not, you need to alter the new domain DNS and either change its nameservers or A/CNAME records, to point to your host.
#2- Then on the hosting side, we add the new domain
Primary domain
If your hosting has just one slot available for the domain, you will need to change the primary domain(if option available), or reach the hosting support and ask them to change the primary domain of your hosting account.
The primary domain usually points to the root, / or public_html folder, so changing your primary domain will point your new domain to your WP website files automatically.
Addon domain
If your hosting package has multiple domain slots available, then you can add the new domain as an addon domain.
Once the new domain is up as an addon domain, you need to go to website files(in the old domain directory) and move them over to the new domain directory.
And then, we need to update the URLs inside your WordPress website database.
#3- In the end, we alter the WordPress database and change the old domain to the new one
WordPress database is a structure that contains all of the website data(theme and plugin settings, post and pages content, and various other data including WP website URLs).
When changing the WP website URL, we need to do two things:
Changing WP URLs inside the database
If you try accessing your website from the new domain at this point, you will be redirected to the old domain. Why?
Because you moved the files to the new domain, and those files are connected to a WP database.
And inside the database, there are two fields that decide the URL of your website.
They are in the options table(wp_options), which can be called otherwise in the prefix part.
Under this table, there are two specific fields that we need- “siteurl” and “home”.
As you can see, they are still showing the old domain, and that’s where we enter our new domain name.
After this is completed, your site should start working from the new domain(URL).
However, there are many more URLs inside the database, that should be changed as well.
This could be page or post URLs(or URLs inside of them), URLs from theme settings, redirection tables or any other URL that had luck to be a part of your database.
This is why there is a second step involved:
Bulk changing WP URLs inside the database
For this purpose, we are using a neat free plugin called “Better Search Replace“.
It is a plugin that you install on your website, select all tables, enter the old URL and new URL, and the plugin gets them all replaced automatically.
You may wonder why we need the first step(with manual URL replacement) when this plugin can do it for us, and the answer is simple- this plugin works from the WP dashboard area, and you can’t access your dashboard area before “siteurl” and “home” fields in the wp_options table get changed.
Once the “Better Search Replace” plugin gets the job done, your WordPress site should work from the new URL.
SEO considerations when changing the WordPress URL/moving it to a new domain
Unless you bought an already used domain, it is safe to say that your new domain has zero backlinks.
The same could be said for your old domain if you didn’t do any marketing, or the site is still very new.
However, if sites are already pointing to your old domain, and especially if you are satisfied with them and your old URL ratings, you should definitely pay attention to this section.
How to pass the link juice/authority of your old domain to the new one?
Luckily for us, engineers invented many things online, and one that we couldn’t live without is redirects.
The purpose of redirect is to pass the traffic(and thus link juice) from one URL to the next, using a code and scheme predefined by you.
There are many codes, schemes, and purposes where redirects are essential, however, we will stay on topic and simply show how you can redirect your old domain to the new one, passing all the traffic and SEO benefits of the old one.
Adding a redirect to your .htaccess file
First, go to your website files in the old domain root folder(either via File Manager or FTP client), and locate the “.htaccess” file.
If you don’t see it, check that you can see all hidden files, or eventually contact your hosting support if they are willing to do it for you. You can also try recreating it, and it should work as long as you can see the hidden files.
Depending on your plugins and whether you edited the .htaccess file before, it could look in various different ways, but here’s the default WP .htaccess file:
# BEGIN WordPress RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
Once you locate it, you should edit it so it looks like this:
RewriteEngine On RewriteCond %{HTTP_HOST} !oldexample.com$ [NC] RewriteRule ^(.*)$ http://www.newexample.com/$1 [L,R=301]
and save it.
Of course, you should change the oldexample.com and newexample.com with your own old and new domain names.
Hopefully, the text above was clear enough and showed you how you can easily update your WordPress website domain name or URL.
However, we ain’t perfect, so if you have any questions or comments about this tutorial, feel free to write them in the comments below, and we will respond as soon as possible.
Or if you aren’t tech-savvy or don’t have the time to learn how to do it, check our cheap WP migration services.
Leave a Reply