Restrict Access to Addon Domains through the Main Domain

Problem:

I do not want to see addon.maindomain.com. How do I do that?

Solution:

The following is an example '.htaccess' code which provides a thorough means of making the Addon domain folders, and their contents, invisible through the main domain by forcing a "404 Not Found" error. This will work both for web browsers and search engines:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/addonfolder/(.*)$
    RewriteRule ^(.*)$ - [L,R=404]
The example rewrite rules will force 'http://www.domain.com/addonfolder/' and any of its contents to report the "404 Not Found" error.

Be sure to replace the 'domain.com' in the example with your hosting account's main domain address and 'addonfolder' with the name of the folder for your Addon domain.

This can also be applied to multiple Addon domain folders through the use of the [OR] option as in the following example in which 3 Addon folders are being reported as "404 Not Found" when accessed through the main domain:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/addon1/(.*)$ [OR]
    RewriteCond %{REQUEST_URI} ^/addon2/(.*)$ [OR]
    RewriteCond %{REQUEST_URI} ^/addon3/(.*)$
    RewriteRule ^(.*)$ - [L,R=404]
  • 29 Users Found This Useful
Was this answer helpful?

Related Articles

URL redirect/rewrite using the .htaccess file

Problem: How do I perform a URL redirect/rewrite using the .htaccess file? Solution: .htaccess...

How to host the Primary Domain from a subfolder (.htaccess)

How do I make a sub directory (or sub folder) act as the public_html for your main domain? The...

Redirects that do not work due to PHP variables

Problem: The redirection of www.yourdomain.com/default.html or index.html to...

Redirect

Problem: How do I create a redirect? Solution: The Redirects tool will allow you to redirect...

Restrict subdomain access to addon domains

Problem: How do I stop people from being able to use the addon domain as a subdomain of the...