How to change my Wordpress site major domain from URL1 to URL2?

I have created a Wordpress site, which looks like this:

I have then created a second domain, which is this:

Now both point to the major domain,

How can I change the major domain to

I have tried to change the Wordpress URL at the WP admin panel, but then error will occur.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

How to configure WordPress to use new domain name


Changing domain for WordPress is easy job. You just go to WP-Admin -> Settings -> General and change WordPress Address (URL) and Site Address (URL). But in case you use Certificate on your WordPress site, changing URL will cause certificate mismatch error. You probably saw errors like these, you will be asked to add security exception before opening site and it will have red lock instead of green.

In short lines, this is what we will do today:

  • Reconfigure nginx to reflect domain changes
  • Generate Let’s Encrypt certificate for your new domain
  • Configure WordPress to use new domain So, let’s start. :)

Step 1 - Generate new certificate

This is based on How to secure Nginx with Let’s Encrypt on Ubuntu 16.40 DigitalOceans tutorial. As this is second time, you don’t need to follow whole tutorial, follow what I wrote down.

We will use Webroot Plugin to generate certificate for your new domain. In case it is you should execute:

  1. sudo letsencrypt certonly -a webroot --webroot-path=/var/www/html -d -d

Take care of --webroot-path, make sure it matches location of your html root folder (where WordPress is installed). This will generate certificate for that can also be used for Successful output should look like:

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/ Your cert will expire on 2016-12-29. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - If you like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: Donating to EFF:

Most important informations are when it expire, and location of it. This should do the job in case of certificates.

Step 2 - Reconfigure Nginx to use new domain name

Create new snippet for pointing to SSL cert

We will start with creating snippet for pointing to new cert. Create it as and open it with favorite text editor. We are going to use nano as it is most easiest.

  1. sudo nano /etc/nginx/snippets/

Content of file should be:

ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;

Configure Nginx server block to use new snippet and domain

You shuold have Nginx server block is located at /etc/nginx/sites-available/default, if you didn’t changed anything yourself. Open it with your favorite text editor.

  1. sudo nano /etc/nginx/sites-available/default

Let’s say it have two parts:

  • Redirector
  • WordPress config

You will know it is redirector by looking at its port. Redirector always listens on port 80 and redirects all traffic to 443/https. It should look like:

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

Change server_name; to


This is it for redirector, now let’s look for WordPress config. You will see it is listening on port 443 instead of 80. First part should look like these:

server {
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        include snippets/;
        include snippets/ssl-params.conf;

        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;


Lines red highlighted should be changed. First change include snippets/; to

include snippets/;

After that change server_name; to


Verify configuration

After every nginx change, you should verify and test config files. Nginx have very powerful command for it:

  1. sudo nginx -t

It will test all your Nginx configuration and report status. You should see something like:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

In case of problem arise, report it here, I will try to help you fix it.

Step 3 - Configure WordPress to use new domain

Wordpress is most easiest part. Just go to your WP-Admin, Settings, General and update WordPress Address and Site Address to new domain. If problem arises here, let’s first analyzes what does it say. Post it here, and I will try to resolve it with you.


And… Here we goes! If everything goes well, you should have fully working WordPress site on new domain. In case of any problem, comment/post, I or any other member here will try to resolve it for you. I hope this will be helpful for you. :)

Hello there,

If you’ve already updated the Home and Site URLs from the WordPress admin panel then you can take the next step and update all the references for the IP address in your database as well.

**Note:**Please before you proceed take a snapshot of the droplet and also create a backup of the site (both files and database). This will ensure that if something goes wrong you can easily restore your site or droplet if needed

There are few ways to update the references in your database and it’s totally up to you which one you’ll choose. You can either change them manually if they’re not many or use an automation tool like a plugin or an external app.

One of the external apps that I’ve used and I know for sure that it’s working okay is:

You need to upload the script in your public_html folder and access in your browser, then you’ll need to fill in your database details and enter the old name (IP address) and the domain name you want to use. Then you can first use the dry-run option and if there are references that need to be updated you can then run the script and update them.

Also, an alternative way is to use a plugin called “Duplicator” it will update all of the paths and references from the dev domain to the main domain. This is why we usually recommend using a plugin called: Duplicator. The plugin will generate a backup for your website’s files and database. Then when you import the files to the new domain, all of the references for the old domain name will be updated properly with the correct ones.

Another option is to use the All-in-One WP Migration plugin. The plugin will do the replacement for you during import. You do not need to use any additional database search and replace

Once this is done you can check the site for any errors as there might be some hardcoded references for the IP address in the files like paths to directories, files and etc.

Hope this helps! Regards, Alex

Btw, it seems my website will have problem sometimes, and it is caused by Let’s Encrypt. It is doing more harm than good?

Can I remove it at this stage now?