1. Home
  2. cPanel Tutorials
  3. How to Stop Addon Domains from Being Accessed By Your Main Domain in cPanel
  1. Home
  2. Help & Troubleshooting
  3. How to Stop Addon Domains from Being Accessed By Your Main Domain in cPanel

How to Stop Addon Domains from Being Accessed By Your Main Domain in cPanel

If you have Addon Domains in cPanel, they can technically be accessed by your primary domain name due to the directory structure of cPanel as show below:

addon-domain1.com – /public_html/addon-domain1
addon-domain2.com – /public_html/addon-domain2
addon-domain3.com – /public_html/addon-domain3

This can be solved by adding the code shown below to your .htaccess file.  This will prevent your addon domains being access through your main domain.  By adding the code below, your visitors will see a 404 error instead of the addon domain name.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon-domain1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/addon-domain2/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/addon-domain3/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
Tip:

The .htaccess file is located directly in the public_html folder of your hosting account.  You can use the File Manager in cPanel or an FTP client to create or edit the .htaccess file.

Updated on February 15, 2021

Was this article helpful?

Related Articles