Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 1 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
add comment

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
add comment

Your Answer

 
discard

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.