Subdomain - fetch files from main domain except config

Discussion in 'Apache' started by PoPSiCLe, Sep 24, 2015.

  1. #1
    Hi.
    I'm currently trying to set up a WAMP-install with subdomains which will fetch the files from the main domain, except for the config-file, which will differ among the subdomains.

    Something like:
    www.example.com -> loads fine, everything works, default config
    test.example.com -> loads the same files as above, except it loads its own config

    I've got the subdomain working (except I had to remove my .htaccess from the main domain, but I'll get around to fixing that later), but I'm wondering if I can do anything to make everything work on the Apache side, or if I need to fix the code running on the main domain to cater for subdomains.

    Any suggestions would be appreciated :)
     
    Solved! View solution.
    PoPSiCLe, Sep 24, 2015 IP
  2. ProxyRadar

    ProxyRadar Greenhorn

    Messages:
    22
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    20
    #2
    Which "config" you wish to be differ? .htaccess ?
     
    ProxyRadar, Sep 24, 2015 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    No. The site has a config.php which will be different for each user (different credentials, different DB etc) - so it would be simpler to just have a main set of files, and then subdomains / subfolders for each separate entity using the system. While I understand that I need to modify some of the code to allow for the files to work as intended, I was just wondering if there was a way to let Apache believe that the files should be served from the main root folder, instead of the current subdomain.
     
    PoPSiCLe, Sep 24, 2015 IP
  4. #4
    You may include different configs like this

    
    /*
    
       Configs directory structure
       ---------------------------
    
       /configs/config.php   - default config
       /configs/webmail/config.php - config for "webmail" subdomain
       ...
    
    */
    
    $legitSubdomains = array('webmail','store','blog','developer');
    $configsRootPath = '/configs/';
    
    if(preg_match('#^(?:([^\.]+)\.)?yourdomain\.com$#', $_SERVER['HTTP_HOST'], $res))
    {
       $subdomain = strtolower($res[1]);
    
       if(in_array($subdomain, $legitSubdomains))
       {
         $configsRootPath.= $subdomain . '/';
       }
    }
    
    require($configsRootPath . 'config.php');
    
    PHP:
     
    Last edited: Sep 25, 2015
    ProxyRadar, Sep 25, 2015 IP
    PoPSiCLe likes this.
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Hm. Maybe that can work. I'll have to have a look see and see if I can change stuff around a bit
     
    PoPSiCLe, Sep 25, 2015 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Thanks. I got it working, now I just need to adjust a few parameters so uploaded files and such are kept together with the subdomain-folders.
     
    PoPSiCLe, Sep 25, 2015 IP