Multiple Domains, One Wordpress running on Linode Virtual Host

Hey Everyone,

I recently got a new domain name and wanted to switch my WordPress site over to that. Unfortunately, this would mean that anyone used to the old domain would be unable to visit the site.

Because of this, I want to have both domains pointing to the same WordPress site, that is set up on a Linode Server virtual host. I haven’t seen any tutorials for something like this and was wondering how I could do that.

Any suggestions?

Just set up your new site the way you want it, then do a server-side redirect (301 or 302) to the new site. So anyone who visits the old one will be automatically redirected to the new one.

I can help you do this in the virtual hosts config if you want.

Well, I want to keep the same website, not make a new one (just adding a domain name). Would that still work?

So let’s say I had oldsite.com and I put a Wordpress site on there. Great.

Then I get newsite.com domain name and I want to use that instead. I’d create the virtualhost, and point it at the same directory as the old one, and edit the Wordpress settings to reflect the new domain name. You might have to edit the database if you can’t do it in the Wordpress admin, but you can use phpmyadmin for that.

You’ll need to change things such as “Wordpress Address” and “Site Address” in “Settings” in the Wordpress admin panel. Maybe refresh the permalinks as well (by changing format, saving, and changing back again).

Then once the newsite.com domain name works just fine, edit the oldsite.com virtualhost with something like:

Redirect / https://newsite.com

Ohh I see what you mean. Can you help me with creating the new virtual host?

So, login to your host. I tend to do everything as root because I’m lazy. But if you don’t, you’ll need to sudo all these commands. Something like this:

nano  /etc/apache2/sites-available/newsite-com.conf

then inside that, you’d put something like:

<VirtualHost *:80>
        ServerName newsite.com
        DirectoryIndex index.php
        DocumentRoot /var/www/newsite.com/
        <Directory /var/www/newsite.com/>
                AllowOverride All
        </Directory>
</VirtualHost>

I also tend to add this:

<VirtualHost *:80>
        ServerName www.newsite.com
        DirectoryIndex index.php
        DocumentRoot /var/www/newsite.com/
        <Directory /var/www/newsite.com/>
                AllowOverride All
        </Directory>
        Redirect /index.php http://newsite.com
</VirtualHost>

because “www” is so 1990s, but there are internet SEO bros out there who think they know it all and insist that websites start with “www” lol.

Anyway, make sure that DocumentRoot points at your existing Wordpress directory.

a2ensite /etc/apache2/sites-available/newsite-com.conf
service apache2 reload

From there, you can go into Wordpress and change the “Wordpress Address” and “Site Address” in “Settings” in the Wordpress admin panel to point at the new URL. If you can’t get in for some reason, try going to the old site and changing from there. Or you’ll perhaps have to change it in the database itself.

Then just use the site for a while to make sure the new address works, perhaps do the SSL stuff with certbot, etc.

Once you have all that done, go back and edit the old site’s config.

nano  /etc/apache2/sites-enabled/oldsite-com.conf

And add a redirect to the new site

Something like this:

<VirtualHost *:80>
        ServerName oldsite.com
        DirectoryIndex index.php
        DocumentRoot /var/www/oldsite.com/
        <Directory /var/www/oldsite.com/>
                AllowOverride All
        </Directory>
        Redirect /index.php https://newsite.com
</VirtualHost>

And reload apache again, and it should redirect to the new one.

If you run into trouble, let me know!