htaccess issues for multiple domains on server

Discussion in 'Web Development and Programming' started by Jim McClain, Sep 12, 2012.

  1. Jim McClain

    Jim McClain Regular Member

    Joined:
    May 31, 2009
    Messages:
    61
    Likes Received:
    9
    Location:
    The REAL Northern California
    I keep putting off this problem and it's been several years now, so I need to fix it. I am being hosted on a VPS and have the main domain and several other domains as sub-folders. The organization is thus:

    • public_html (http://maindomain.net)
      • number1domain (http://www.number1domain.com)
      • number2domain (http://number2domain.org)
      • number3domain (http://number3domain.net)
    Each one of those domains should appear to be stand-alone domains, with no reference to the main domain (unless it IS the main domain). In other words, if someone types in their browser "www.maindomain.net/number2domain" OR "http://number2domain.maindomain.net" they should get ONLY "http://number2domain.org". If they happen to type in "www.maindomain.net" they should get ONLY http://maindomain.net.

    I have tried so many ways using htaccess, using rewrite conditions and rules in only maindomain.net's root folder and individual htaccess files in each of the domain folders, or a combination of both. I can not seem to get them to obey all the rules. My current setup for number2domain.org is an htaccess file in that folder:

    Code:
    Options +FollowSymLinks
    DirectoryIndex index.php index.html index.htm
    RewriteEngine on
    RewriteBase /
     
    RewriteCond %{HTTP_HOST} ^number2domain\.maindomain\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.number2domain\.maindomain\.net$
    RewriteRule ^/?$ "http\:\/\/number2domain\.org" [R=301,L]
    This causes all calls to number2domain.maindomain.net to be redirected to http://number2domain.org, which is good. But the problem remains that calls to www.maindomain.net/number2domain do not get redirected at all.

    Any help from those who understand htaccess and mod_rewrite much better than I would be appreciated.

    Thanks,

    Jim
     
  2. Jim McClain

    Jim McClain Regular Member

    Joined:
    May 31, 2009
    Messages:
    61
    Likes Received:
    9
    Location:
    The REAL Northern California
    GREAT! I did not want to create a post with numerous links to non-existent websites. I thought the [ plain ] tags were what prevented that, so, since there's no button that will add that BBCode, I entered each one manually. What a waste of time. I apologize for the stupid links.
     
  3. Dan Hutter

    Dan Hutter aka Big Dan

    Joined:
    Jul 20, 2006
    Messages:
    1,412
    Likes Received:
    515
    Location:
    New York
    Jim, I wrote an article about this problem a couple years back: http://www.emailquestions.com/general/2802-cpanel-addon-domains-mod_rewrite.html. The problem is the .htaccess in the senior directory (public_html) effects the subdirecties. So pubic_html/domain1.com and public_html/domain2.com are being rewritten by the htacess rules in public_html.

    The solution is to host your additional domains above public_html. You can do this when you adding the domain at the add-on domain screen. The default path is pubic_html/domain1.com just remove the public_html part and all your domain will be served from the domain1.com folder.

    If you have access to WHM you may have to enable domains being served outside of public_html/: WHM > Tweak Settings > public_html subdomains only set to off

    The only way to do this for existing domains, I believe is to delete the add-on domain and re-add it and then copy the files manually. It's probably easiest through cPanel File Manager vs FTPing everything down and reuploading. Just remember to re-add your email addresses and such after adding the domain again as they're deleted when you delete the domain.
     
    cpvr and Jim McClain like this.

Share This Page