Redirect subdomain of addon domain to related domain

1

As you know, when add a new domain in your cPanel, cPanel use an internal subdomain to name this domain

ie :

The main domain of your cPanel account is : maindomain.com

You add domain : addondomain1.com

cPanel will create internally a subdomain like addondomain1.maindomain.com

What is issue, in some cases, pages of your site maindomain.com will be accessible (also index by google) through URL addondomain1.maindomain.com

To fix this, create a file nginx.conf in the folder of related website, and add the following by adapting to the concerned domain values :

if ($host = addondomain1.maindomain.com) {
rewrite ^/(.*) https://www.maindomain.com/$1 permanent;
}
if ($host = www.addondomain1.maindomain.com) {
rewrite ^/(.*) https://www.maindomain.com/$1 permanent;
}

 

After, go to Nginx manager in your cPanel, and reload nginx