How to Restrict Addon Domains Folder Accessing from Main Domain in cPanel?

If you are running your websites under cPanel and have addon domains linked with subdomains and your web host provider force to set all the domains inside public_html as below there might be an issue that your addon domain content can be accessed via the main domain as well.


example.com – /public_html/domain
example1.com – /public_html/domain1
example2.com – /public_html/domain2

To overcome this issue, you can add the below rule in your .htaccess file. This will prevent Main domain to access the addon domain folder.  If the addon domain folder is accessed through your main domain, it will give the 404 error message.

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

Related Articles

Fix : The response is not a valid JSON response in Wordpress.

You may receive the below error while updating the WordPress post.  The response is not a...

How to create a catch-all email address in cPanel?

With a catch-all email, you can catch all the emails sent to the users that are not created or...

How to install Moodle using Softaculous in cPanel?

You need to have PHP extension fileinfo enabled for your domain and PHP version equal to or...

How To Automatically Delete Forwarded Mails in cPanel?

You can use cPanel email forwarder option to forward your emails to any other email account....

cPanel error - MySQL: Server sent charset (255) unknown to the client.

Websites hosted on the same cPanel are giving mysql errors. Log is showing  MySQL: Server sent...

  • 0 Users Found This Useful

Was this answer helpful?