How to Rebrand (or Change Domain Name) in WordPress

Share

This post describes the steps one can take to rebrand or change a domain name in WordPress.

If you have been on this site before, you may have noticed a name change. Before today, this site had a domain name websiteforstudents.com. If you look at your browser address box, you will see geekrewind.com.

A redirect is in place to send all web traffic from websiteforstudents.com to geekrewind.com. I’m going to show you how I did it in just under an hour.

If you have a website or blog built in WordPress, and you have full access to your server’s console either via SSH or direct connection, then the step below will show you how to switch a domain or rebrand a website when using WordPress.

Changing a domain name in WordPress

As mentioned above, users can change or rebrand their websites hosted with WordPress easily, and the steps below describe the process.

Register a new domain name

Before migrating to a new domain, you’ll first want to register a domain name that you want to switch to.

If you haven’t registered a domain name before, the post below shows you how to do that.

How to register a domain name

Once you have registered the domain name, make sure to point the name to the same server host IP as your current website.

Create a new virtual host or server block

Once the name is registered a DNS is updated to point to the same host (A record) IP, go and create a new virtual host when using Apache or server block if using Nginx.

If you haven’t created a virtual host or server block, below is how to do it.

Now each environment will be different. Yours might have unique parameters and definitions.

I use Nginx here. My new server block looks similar to the one below. websitesforstudents.com will be redirected to the new domain geekrewind.com:

server {
        listen 80;
        listen [::]:80;
        server_name websiteforstudents.com www.websiteforstudents.com;
        return 301 https://$host$request_uri;

        include snippets/well-known.conf;
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.websiteforstudents.com;

        return 301 https://geekrewind.com$request_uri;

        include snippets/well-known.conf;
        ........................................
        ........................................
}

server {
        listen 443 ssl http2;
        listen [::]:443 ssl;
        server_name websiteforstudents.com;
        
        return 301 https://geekrewind.com$request_uri;

        include snippets/well-known.conf;
        .........................................
        .........................................
}

I have three server blocks. The first one is simply redirecting HTTP to HTTPS. The second block is redirecting WWW to the new non-WWW domain. The last block is redirect non-WWW to the new non-WWW domain.

Blocks with listen 443 and http2 definitions have Let’s Encrypt SSL certificate configurations for both new and old websites.

Below is how to request Let’s Encrypt SSL certificates

For the current website that is referenced in the current server block, make sure to replace all current domain names with new domain names in the current server block file.

Update WordPress database

After creating a new server block and updating the current with a new domain name, go and update WordPress database tables and replace the current URLs with a new one.

Sign on to your MySQL server.

sudo mysql -u root -p

Type a password or simply press Enter to log on.

There, change to your WordPress database.

use wpdatabse;

Next, run the commands below to view the current URLs.

SELECT option_name, option_value FROM wp_options WHERE option_name IN ('siteurl', 'home');

That will display lines similar to the one below:

+-------------+------------------------------------+
| option_name | option_value                       |
+-------------+------------------------------------+
| home        | https://websiteforstudents.com     |
| siteurl     | https://websiteforstudeents.com    |
+-------------+------------------------------------+
2 rows in set (0.00 sec)

Next, run the commands below to update the values for the home and site tables.

UPDATE wp_posts SET guid = replace(guid, 'https://websiteforstudents.com','https://geekrewind.com');

Next, run the commands below to update the post_content value in the wp_posts table:

UPDATE wp_posts SET post_content = replace(post_content, 'https://websiteforstudents.com', 'https://geekrewind.com');

Next, run the commands below to update the meta_value value in the wp_postmeta table:

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'https://websiteforstudents.com', 'https://geekrewind.com');

Exit the database console.

Double-check your work

Once the changes above have been made, double-check your work to make sure you’re not missing anything.

If all is working, restart Nginx or Apache and hope that all is well.

That should do it!

Conclusion:

This post showed you how to rebrand or migrate to a new domain in WordPress. If you find any error above or have something to share, please use the comment form below.