Restrict Access to Addon Domains through the Main Domain

Restrict Access to Addon Domains through the Main Domain

On cPanel server, addon domains are linked with subdomains and sometimes, web hosting providers force to create all addon domains inside public_html folder as follow:

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

The above structure will allow to access addon domains content via main domain as well. You can prevent this using .htaccess rule as follow:

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

Above code will redirect to 404 page when you try to access addon domains folder using main domain.

Scroll to top