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

  • 0

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]

Was this answer helpful?

« Back
Sign up for a newsletter

chat