Change domain name WordPress, the SEO friendly way

Change domain name WordPress, the SEO friendly way

How to change domain name of your WordPress site the SEO friendly way, without losing PR and link juice

I recently changed domain for this blog from egeek.dk to egeek.io. There are two parts of changing your domain or moving your site to a new host and domain – the technical part, and the SEO part where you try to preserve your search engine rankings. Doing it the right way will save you a lot less trouble in the future, and make you keep most of your hard earned SEO work. On the other hand, doing it wrong can have fatal consequences on your rankings in the search engines.

I’ll narrow it down and describe how I did it, and how you should do it too.

In my case I wanted to change domain from egeek.dk to egeek.io on a running WordPress site. I was not switching host/server, but just wanted to “rebrand” my site with a new domain. Whether you are in the same situation and want to rebrand your site, or want to switch host and domain, you can use these steps as a guideline.

I’m currently running this blog on IIS in a Windows Server environment, but the fundamentals are the same, and the following steps can be incorporated, should you run your site/blog on Apache, Nginx or on a LiteSpeed server in a *nix environment.

Disclaimer

Before starting out, I want to stress that changing your domain from olddomain.com to newdomain.com will affect your search engine rankings in the beginning. After you do a switch Google will index both of your sites, where after olddomain.com will slowly dissapear from the search results. I’ve had pages indexed with meta titles and descriptions chosen by Google, instead of the meta-data I chose for the pages (yeah, Google can do that). After the switch these pages are currently indexed with my new domain, and yet again Google has chosen meta titles and descriptions, though different (and much worse) than before. I had top 1 placements in Google with feature images and snippets, which are now gone after I changed domain. It’s a part of the process, but I’m positive the rankings and feature snippets will come back up, when everything is rolled out completely. It’s inevitable for things like these not to happen, as Google needs to reindex your whole site again. Don’t put too much concern into this though, as things will smooth out, and if you play it right, you’ll be back up where you were before. That’s what this guide is about.

Table of content

1. Domain name
2. Site and bindings
3. Change WordPress address
4. 301 redirects
5. Rename SQL database
6. Add properties in Google Search Console
7. Change address in Google Search Console
8. Submit sitemaps in Google Search Console
9. Update Google Analytics account and tracking code
10. Fetch site and submit to index
11. The afterwork

1. Domain name

First off, buy your desired domain and set up DNS records to point to your server or host.
The time from buying a new domain to when it’s actually registered and active can vary from less than an hour to 24 hours (typically). It takes longer for DNS servers to sync and know where to point your domain at. Your ISPs DNS servers might get your new DNS records fast, where as other people’s ISPs DNS servers can take a bit longer, or vise versa. Give them a day or two to update and have your records in place.

I ordered my domain from a company, who registered my domain with their DNS servers. I’m using another DNS provider for all my domains (to have full control and have them gathered in one place), so I had to change DNS servers for my domain, which probably made it take longer, than if I had just used the domain resellers DNS servers.

2. Site and bindings

As I was renaming my existing site and not moving to a new host, I went to my webserver, stopped the Application Pool and site in IIS, renamed my website folder to match the new domain, renamed the Application Pool associated with the site and the site itself. Pretty straight forward.

Now, we want people (and Google) to be able to reach our site on both our domains to avoid broken links on sites that link to us, broken search results in Google, and people who don’t know our new address yet to be able to reach us. Don’t be afraid of duplicate content, I’ll dig into this in “301 redirects“.

So now that our site is renamed, or maybe in your case moved to a new host, we need set up bindings so that the site can be reached from olddomain.com and newdomain.com. In IIS you just right click your site and choose “Edit bindings…”, then add one binding at a time for both www and non-www for both domains, so that you end up with 4 bindings in total.

IIS bindings

For Apache you need to create multiple ServerAlias within your VirtualHost.

3. Change WordPress address

Now that our site responds to both of our domains, we need to log in to WordPress and change our WordPress and site addresses to match our new domain before going to next step, to avoid complications logging in, after we create redirects.

You do this from Settings > General

Wordpress address

4. 301 redirects

Currently our site can be reached from both olddomain.com and newdomain.com which results in duplicate content, which we are not interested in. Futhermore search engines and people linking to us, link to our old domain, and we don’t want all these inbound links to break, therefor we need to redirect them to our new domain.

There are two types of server redirects:

  • 301: Site or resource has moved permanently
  • 302: Site or resource has moved temporarily

The ladder (302) is only used in special occasions and should not be used in our situation or for SEO purposes in general. Instead we want to tell the search engines that our site has moved permanently. This way we will retain our search engine rankings, which would be lost with a 302 redirect.

As I’m hosting my WordPress site on IIS in Windows, I’ll create a rewrite rule in web.config, which will handle my 301 redirects. If you are running eg. Apache, you’ll need to create redirects in your htaccess file. Read Apaches URL Rewrite Guide if you are in that situation.

For IIS you will first need to have the URL Rewrite extension installed. If you haven’t already, download and install it.

Next, open your web.config and place your rewrite rule within

[xml]<system.webServer>rule goes here…</system.webServer>[/xml]

Here’s an example of a web.config that will 301 redirect all requests from www to non-www (switch it around if you currently use www prefix), and furthermore redirect all requests to newcomain.com. Practically that mens if you type http://olddomain.com/blog/my-awesome-post/ in your browser, you will be redirected to http://newdomain.com/blog/my-awesome-post/.

Caution: Be aware that you might have other configurations in your web.config, such as compression, caching, etc, why you should insert the rewrite rule yourself, and not just copy/paste my whole example.

[xml]
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Canonical Hostname">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^newdomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://newcomain.com/{R:1}" redirectType="Permanent" />
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
<httpErrors errorMode="DetailedLocalOnly" />
</system.webServer>
<system.web>
<compilation defaultLanguage="c#" />
</system.web>
</configuration>
[/xml]

That’s it for rewriting. Now all links in search engines and on other sites linking to us will be redirected to the same content, but on our new domain, and our link juice and PR will only be slightly affected.

5. Rename SQL database

If your MySQL database and user have your old domain in their names, you might want to rename your database and/or user to match your new domain. If not, you can skip this step, as it’s not crucial. Typically databases and users are named domain_com though, and to keep things nice and clean, we would want to rename them to match our new domain.

It’s not so easy to rename your database per say, and also for security reasons, it’s better to create a new database associated with a new user, and then copy the content from your old database to your new database.

5.1 Start by creating a new user and database. Previsously I wrote a blog post on how to, which you can find here: Create MySQL user and database

5.2 Create a MySQL dump of your old database. Mysqldump is a tool located in “C:\Program Files\MySQL\MySQL Server x.x\bin”, so open up Command Prompt and CD to that dir, then run:

mysqldump -u root -p old_database > old_database.sql

Now copy the content of the old database to your new database:

mysql -u root -p new_database < old_database.sql

5.3 Open up “wp-config.php” located in your website root and adjust MySQL settings to match your new database, username and password:

[php]
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘newdomain_com’);

/** MySQL database username */
define(‘DB_USER’, ‘newdomain_com’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘MyNewPassword’);
[/php]

5.4 Test that your website works and you are able to log in to the backend.
When you are completely sure that everything works, delete your old user and database.
Move your mysqldump file from “C:\Program Files\MySQL\MySQL Server x.x\bin” to a safe location and keep it as a backup.

Delete MySQL user:

mysql -u root -p drop user ‘old_user’@’localhost’

Delete MySQL database:

mysql -u root -p -e drop database old_database

6. Add properties in Google Search Console

We need to notify Google about our domain change, but first we need to add two new properties matching our new domain – with and without www.
Log in to Search Console and click “Add property” in top right corner.
Remember to verify your domains and set prefered domain (with or without www, depending on your choice, but it have to match with your 301 redirect).

Notice that I keep my old properties (www.egeek.dk and egeek.dk) as well. Don’t delete them!

Google Seach Console - Add property

7. Change address in Google Search Console

Now that our new properties are created, we need to notify Google about our domain change.

Respectively click on your old properties > click the wheel in top right corner and chose “Change of address”.

Google Search Console - Change address

Pick your new domain in the drop down, check that your 301 redirects are working, confirm verification methods are still present and click “Submit”.

Google Search Console - Change address confirm

After submitting address changes in Search Console, Google will start the process of changing all your links in its index. It’s a long process that will not happen overnight. You will experience your site being indexed with both your old and new domain, but results pointing to your old domain will decrease over time. Have patience.

8. Submit sitemaps in Google Search Console

Let’s help Google crawl our content by submitting sitemaps for our new domain.
From Search Console pick your prefered newly created property (domain.com or www.domain.com).
In the left menu go to Crawl > Sitemaps and add the sitemap(s) for your site.

If you are using Yoast SEO and have “XML Sitemaps” enabled, you can get a list of all your sitemaps by going to domain.com/sitemap_index.xml. Add each one of them in Google Search Console.

Google Search Console - Sitemaps

9. Update Google Analytics account and tracking code

Now that everything else is renamed, let’s not forget our Analytics account.

Log in to Google Analytics, pick your site and click on “Admin” in the top menu. Depending on how you named your Account, Property and View, click on “Settings” for each property, and you will be able to rename the respective property.

Google Analytics

Remember to change the URL as well to match your new domain.
In the column “Property”, select “Property Settings” and change “Default URL”.

Google Analytics - Change Property Default URL

In the column “View” select “View Settings” and change “Website’s URL”.

Google Analytics - Change View Websites URL

Check your tracking code on your WordPress site, to see if it contains your old domain. If not, you are good. Should your tracking code contain your old domain, update your tracking code to a new and generic one. You can find your tracking code by clicking “Tracking Info” > “Tracking Code” in the property column in the admin section of Analytics.

Google Analytics - Tracking code

10. Fetch site and submit to index

We now got everything set and want to notify Google about our changes. Basically that means asking Google to recrawl and reindex our website.
Go to Search Console and select your new domain. In my case that’s egeek.io, as I’ve chosen the non www-version to be my prefered domain as I’ve explained earlier on.

In the left menu select Crawl > Fetch as Google. Now click the “Fetch and render” button and wait a minute. When fetching is complete you get a button saying “Submit to index”. Click it and select “Crawl this URL and its direct links”, then click “Go”.

Fetch as Google

11. The afterwork

We’ve moved our site and started the whole reindexing process, but we want to make sure everything goes smooth, so keeping an open eye especially for the next couple of weeks is a very good idea.

Things you should do now:

  • Wear belt and braces! Make sure to recheck everything. Search Google for your top pages, check that the 301 redirects work. Check Google Search Console and Analytics receive data from your website. Some statistics from Search Console can be days delayed, so don’t panic about this, but do as much checking as you are able to.
  • Reach out to sites linking to you and ask them to manually change their links to your new domain. This helps speeding up the process for the search engines.
  • Make the same adjustments as described in this guide to Bing Webmaster Tools, or create your site there, if you are not already using it.
  • Monitor 404 errors in Google Search Console and redirect them to your new domain. You can create redirects with “Quick Page/Post Redirect Plugin” for WordPress.
  • Google is your friend, monitor Search Console and Analytics daily, especially the first couple of weeks.
  • Tell the world about your new site/domain. Do a big content push to get noticed and get inbound links. Create a launch event that promotes your site, and reach out to people on social media.

If you found this guide useful please throw a comment below.
You are also more than welcome to come with additions or suggestions to this guide.