4

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?

3

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.

| improve this answer | |
  • 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 '16 at 4:26
0

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.

| 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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