Redirecting a secure domain in Plesk

- by

There are several ways to make two domains resolve to the same content in Plesk. The easiest option is to setup a Domain Alias. That way, domain1.com and domain2.com both serve the same content from the same subscription.

This worked great for non-SSL domains, but if you have a secured domain, the redirection will be detected by modern browsers and a certificate warning appears. Not what we want.

Another way to achieve the same thing is to create a separate subscription in Plesk, then change the Hosting Settings to Forwarding. This will result in a search engine friendly 301 redirect, but again we have that certificate issue to deal with. Since the redirected domain no longer has its own file structure, the Let’s Encrypt extension is unable to issue a separate certificate for the second domain. Not good either.

The solution, it appears, is a manual addition of a piece of code to the NGINX directives. This will only work if NGINX is enabled in your Plesk setup (it is by default as of Plesk Onyx). Let’s see how to do it.

Step by Step Instructions

Create a new subscription for the domain you’d like to redirect. In our example, let’s use new-domain.com as the current domain that has a subscription, but you’ve got another domain you want to redirect to the above. Let’s call that one old-domain.com. This domain needs its own subscription in Plesk. Don’t worry about adding any content there.

Once setup, head over to Websites and Domains is the subscription and select Apache and NGINX Settings.

Towards the bottom of this ever so slightly intimidating list we’ll find an empty field into which we can add our own code, under Additional NGINX Directives.

We’ll add the following to this box, replacing old-domain.com with the domain you’d like to redirect to. In essence, this is telling NGINX to use the location in brackets for the top level location of our current domain. Here’s a cut-and-paste friendly version:

location = / {
     return 301 https://old-domain.com;
 }

And that’s it! Now your new domain will redirect to the old domain, while retaining all SSL properties. There’s no need for a new certificate either, and search engines will make a note when the bot comes crawling the next time. Furthermore, all deep links will be retained that way too.

Thanks to Nikita Nikushkin from Plesk for bringing this to my attention.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

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