Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an add-on domain in my cPanel website. The root directory for it is under the root of the hosting. How can I prevent access through the main domain?

For example, addondomain.com is configured to serve up files from public_html/addondomdain. How do I prevent people seeing the files at maindomain.com/addondomain and only when viewing them at addondomain.com?

share|improve this question
up vote 3 down vote accepted

This rewrite rule (in public_html/addondomain/.htaccess) will handle redirection for you, should a visitor land at a domain.com/addondomain/ path:

RewriteEngine on
RewriteCond %{HTTP_HOST}       !addondomain\.com$
RewriteRule [addondomain]?(.*) http://www.addondomain.com/$1 [R=301,L]

The rewrite condition instructs mod_rewrite to match on requests where the requested domain name does not end in "addondomain.com" (to include the primary domain and all its subdomains) and the rule instructs mod_rewrite to remove the addondomain subdirectory from the request path (if it appears) and direct the user to the add-on domain name.

share|improve this answer
Thanks for that answer. – paulmorriss Jun 14 '12 at 8:29
I'm having the hardest time with this. It works when only the directory is in the URL (domain.com/addondomain/). However, as soon as I add a filename to the URL, it simply loads the specified page (domain.com/addondomain/index.html). I've tried dozens of solutions and wonder if there is something within cPanel that the host is using to override my rewrite. – Sparky Mar 10 at 4:26

There is no way to hide the addon domain subfolder on your root domain, as it is literally a directory on your website root. You can use an htaccess rule to prevent people accessing it, or you can simply forward it to the subdomain.

share|improve this answer
Can you please give an example of a rule that would do that then? – paulmorriss Jun 13 '12 at 16:05
On second thoughts, preventing access to the subfolder altogether would most probably prevent access to the addon domain also. I think your best bet is to do a redirect from within cPanel. – Oliver G Jun 13 '12 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.