How to make .htaccess to handle two domains?

Discussion in 'Apache' started by johnking06, Jan 21, 2011.

  1. #1
    I have two domains on the same server. primary_domain.com and secondary_domain.com.

    I want
    http://primary_domain.com => {root}/primary_folder/primary.html
    http://secondary_domain.com => {root}/secondary_folder/secondary.html

    Is it possible to use the same .htaccess to handle both domains?
    I can do it for one domain: primary_domain.com with RewriteCond and RewriteRule, but not for the second domain: secondary_domain.com. Any suggestions?

    Thanks.
     
    johnking06, Jan 21, 2011 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    RewriteCond with HTTP_HOST should work fine.
     
    mwasif, Jan 22, 2011 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    place the htaccess file in {root} so that you don't forget where it's at, then create symlinks pointing to that htaccess file from primary_folder and secondary_folder.
     
    joebert, Jan 25, 2011 IP
  4. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Generally you just place a .htaccess in the root directory for each of the domains. So you would have a seperate .htaccess file. for each
     
    srisen2, Jan 26, 2011 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    srisen2 is right, you need to copy the .htaccess file to both directories and both domains are mapped to different directories. I think symlink will not work for .htaccess.
     
    mwasif, Jan 28, 2011 IP