Hello everyone,
I bought a new domain for my website, and now I managed to successfully add it to my droplet, to the point where now I have two domains pointing to the same droplet:
Both domains access the same website from my browser, but the default appears to be openplcproject.com where I want it to be autonomylogic.com. If I launch autonomylogic.com on my browser, the browser address changes to openplcproject.com. Can I invert this behavior? I will eventually phase out openplcproject.com over time, but right now I don’t want it to be disconnected as many users are still using that domain. So ideally it would be even better if openplcproject.com was directed to a specific page saying that openplcproject.com is now autonomylogic.com and then redirect the user automatically after a few seconds. How can that be done?
Thanks!
Thiago Alves
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!
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.
Hi there,
Changing your WordPress website domain name would require a few steps, and I recommend that you first take a backup of your Droplet so that in case anything goes wrong, you can revert to a working version of your server.
WordPress site and home URLs
You would need to start by updating your WordPress site and Home URLs to the new domain name:
Log in to your WordPress Dashboard for the site hosted on
openplcproject.com
.Navigate to “Settings” > “General.”
Update the “WordPress Address (URL)” and “Site Address (URL)” fields to
https://autonomylogic.com
.Save the changes.
This will update the internal WordPress configuration to use the new domain.
If the options to change the WordPress Address and Site Address URLs are not available in the WordPress Dashboard, you can modify these settings by editing the
wp-config.php
file.Here’s how to do it:
Access the File System: Using an FTP client or your hosting provider’s file manager, navigate to the root directory of your WordPress installation.
Find the
wp-config.php
File: This file is located in the root directory of your WordPress installation.Open the
wp-config.php
File: Edit the file using a text editor.Add or Modify the Following Lines: These lines define the WordPress Address (URL) and Site Address (URL). Replace
"http://autonomylogic.com"
with your actual URL.Save and Close the File: Once you’ve made the changes, save and close the file.
Clear the Cache: Depending on your setup, you may need to clear the cache on your web server and your browser to see the changes take effect.
Check the Site: Visit your site at the new domain to make sure everything is working as expected.
Apache virtual host update
Once this is done, you will need to update your Apache configuration to define the new domain name.
First start by accessing your server via SSH:
Open the Apache Configuration File: Find the configuration file for your site, it should be located at
/etc/apache2/sites-available/your-site.conf
Modify the ServerName Directive: Look for the
ServerName
directive in the file and change it to your new domain name. If you have aServerAlias
directive for the old domain, you may want to update that as well:Save and Close the File: Once you’ve made the changes, save and close the file.
After that check the
/etc/apache2/sites-available/
directory and see if you have a separate virtual host for the HTTPS version, you can use thels -l /etc/apache2/sites-available/
to see the availalbe virtual hosts in that directory.Reload Apache: Run the following command to reload Apache and apply the changes:
Issue a New SSL Certificate with Certbot
Next, as the SSL certificate will be still for the old domain, you will have to use Certbot to request a new certificate for your new domain.
Run the following command, replacing
"autonomylogic.com"
with your actual domain:Follow the Prompts: Certbot will guide you through the process, including verifying domain ownership.
Reload Apache Again: After obtaining the certificate, reload Apache again to ensure the new certificate is being used.
Test Your Site: Access your site via HTTPS to ensure that the SSL certificate is working correctly.
By updating both the Apache configuration and the SSL certificate, you’ll ensure that your site is accessible at the new domain name and that the connection is secured with HTTPS. Make sure to back up any configuration files before modifying them, as incorrect changes can lead to issues with your server.
As this requires a few steps, I would like to mention again that it is best to make sure that you have a backup of your server before you proceed with this!
Hope that this helps!
Best,
Bobby
Heya,
In such cases I recommend using WP-CLI. WP-CLI provides a command-line interface for many actions you might perform in the WordPress admin. For instance,
wp plugin install --activate
(doc) lets you install and activate a WordPress plugin:https://wp-cli.org/
In the site are the steps on how to install it on your Droplet.
Here’s a step-by-step guide on how to switch your domain using WP-CLI:
Backup Your Database: Before making any changes, it’s essential to backup your WordPress database in case something goes wrong.
Search and Replace: Run the
search-replace
command to replace the old domain with the new domain. Replaceold-domain.com
with your current domain andnew-domain.com
with your desired domain.If your site uses
https
, ensure you replacehttp
withhttps
in the above command accordingly. Update WordPress and Site URL (if they are not hard-coded inwp-config.php
):Flush Rewrite Rules: To ensure that the site’s permalinks work correctly, you might want to flush the rewrite rules.
Update Your DNS: Make sure to update your DNS settings to point the new domain to your DigitalOcean droplet’s IP address.
Update
.htaccess
: If there are domain-specific rules in your.htaccess
file, make sure to update them.Update SSL Certificate: If you’re using an SSL certificate, you’ll need to obtain a new one for the new domain or update your current one to support the new domain.
Test the Site:
By following these steps, you should have your WordPress site functioning correctly on the new domain. Remember, domain propagation can take some time (up to 48 hours, though often much less), so you might not see the changes immediately.
Heya,
The steps provided by Bobby are what you need to get this sorted. I would like to share a question which was previously asked in our community on the same topic.
https://www.digitalocean.com/community/questions/change-url-in-wordpress
Regards