The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Preventing subdomain access for addon domain

Discussion in 'General Discussion' started by Wolvenmoon, Oct 15, 2009.

  1. Wolvenmoon

    Wolvenmoon Registered

    Joined:
    Oct 15, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I was directed to ask here from v7n. Not sure if, as a user of cpanel, this forum is for me. It does seem to be a more advanced question.

    Okay, so I have an account with a webhost. My webhost has basically told me to buy a second account to do this. The primary domain name for the account is wolvenmoon.com. I have an addon domain, garuvul.com, for the account.

    The current behavior is that a user can type:

    randomfakesubdomain.wolvenmoon.com and get an error
    garuvul.com and get to garuvul.com
    garuvul.wolvenmoon.com and get to garuvul.com
    wolvenmoon.com/garuvul/ and get to garuvul.com

    This works fine for these two sites, but I've recently come across a project I need to keep seperated from my alias of 'Wolvenmoon'. So it requires its own domain name and should not be accessible from wolvenmoon.com

    So here's my desired behavior!
    randomfakesubdomain.wolvenmoon.com redirects to wolvenmoon.com
    garuvul.com goes to garuvul.com
    garuvul.wolvenmoon.com redirects to wolvenmoon.com
    wolvenmoon.com/garuvul/ gives a 403 error message ( I can customize error messages, so I'll set my 404 and 403 to the same page and when troubleshooting switch them )


    So, I don't know the first thing about what I need to do to make this happen. Can anyone help me do this / point me in the right direction?

    Thanks for your time! I really appreciate any help I get!
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I assume you're on cPanel 11.24 or later with the X3 theme. You can see if this is true for your web hosting account by checking the left side column for entries labeled "cPanel Version" and "Theme." If you are not on the X3 theme or are not on cPanel 11.24, you will not (easily) be able to do this.

    I recommend making a full website backup before doing this in case something goes wrong, you can just have your hosting company put everything back to the way it was. Not having a backup can make this process much more time-consuming later on if something doesn't work as you intend it to. You can do this by clicking the Backups Wizard icon in cPanel.

    After that is done, let's take care of the first 3 items:

    1. Add *.wolvenmoon.com as a subdomain, have it serve content from public_html - wildcard subdomains such as this usually take precedence over all subdomains, including those generated by addon domains.
    2. If you don't want the subdomain to appear in the browser's URL bar, you could always add something in .htaccess or your website's script to redirect users not accessing the page via wolvenmoon.com to wolvenmoon.com

    The bottom issue is more tricky. What you could do is remove the garvul addon domain (temporarily - DO NOT DELETE THE FILES) and immediately re-create it such that it is serving content from a location outside public_html (e.g. ~/garvul rather than ~/public_html/garvul where ~ represents the house icon you see in the cPanel interface). Then move your files from public_html/garvul to garvul. If there are scripts running on garvul.com, you may need to perform some minor reconfiguration to ensure they become fully operational again.
     
  3. Wolvenmoon

    Wolvenmoon Registered

    Joined:
    Oct 15, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Thank you!

    I think this finishes off my problem. Here's my .htaccess for anyone that comes in here via google:

    Code:
    RewriteEngine On
    
    #this will redirect any attempt to use wolvenmoon.com or www.wolvenmoon.com to access garuvul, to wolvenmoon.com
    
    RewriteCond %{HTTP_HOST} ^(www\.)wolvenmoon\.com [NC] 
    RewriteRule (.*) http://wolvenmoon.com/ [P]
    
    #this will redirect any attempt to use garuvul.wolvenmoon.com or www.garuvul.wolvenmoon.com to access garuvul, to wolvenmoon.com
    
    RewriteCond %{HTTP_HOST} ^(www\.)?garuvul\.wolvenmoon\.com [NC] 
    RewriteRule (.*) http://wolvenmoon.com/ [P] 
    
    #this will redirect any other attempt to use anything other than garuvul.com to access garuvul pages, to garuvul.com
    
    RewriteCond %{HTTP_HOST} !^garuvul\.com [NC] 
    RewriteRule (.*) http://garuvul.com/$1 [P]
    ldcdc in this thread: Help with some cpanel stuff - Page 2 - Webmaster Forum wrote most of the .htaccess for me.

    Thanks for your help! I would never have tried to move it below public_html - I thought that wouldn't work! :D
     
Loading...

Share This Page