How to Rebrand (or Change Domain Name) in WordPress

|

,

|

This post provides a step-by-step guide to rebranding or changing a domain name in WordPress. Thus, it starts with registering a new domain name, creating a new virtual host or server block, and redirecting traffic from the old domain to the new one. The post then shifts to updating the WordPress database and verifying the…

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

You may have noticed a name change if you have been on this site before. Before today, this site had a domain name, websiteforstudents.com. However, 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 will show you how I did it in under an hour.

If you have a website or blog built in WordPress, and you have full access to your server’s console 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 easily change or rebrand their websites hosted with WordPress, and the steps below describe the process.

Register a new domain name

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

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, 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; 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. For example, 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 redirects WWW to the new non-WWW domain. Finally, the last block redirects 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 referenced in the current server block, replace all current domain names with new ones 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 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 ensure you’re not missing anything.

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

That should do it!

Conclusion:

This post showed you how to rebrand or migrate to a new domain in WordPress. Please use the comment form below if you find any errors above or have something to share.

Like this:



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.