#1
  1. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124

    .htaccess: multiple document roots based on IP


    Hi,

    we have a static IP to our office and a dedicated server for all our client's website (off site, at some secret location near slough).

    Ideally I'd like to be able to client deploy test sites on the final domain/url and want to do something like this

    Code:
    if(client ip == our ip) {
         documentRoot = /path/to/dev/space
    } else {
         documentRoot = /path/to/live/space
    }
    is this possible in .htaccess?

    (yes, I'm using apache!)
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    Let's see if I understand this correctly. You have two servers, one is your dev/preview server located in your office and one is your production server located in a data center. You'd like to have one Apache config that's shared across both servers but that uses a different DocumentRoot based on whether you're in the office or not

    It sounds like your goal is to have your dev/preview as close to production as possible . If that's the goal, I don't think you're going to reach it with this approach because you'll need clientdomain.com to resolve differently, and that doesn't mimic production very well.

    I believe the common approach is to use two DNS entries and two VirtualHosts, which results in two websites with two DocumentRoots. Set DNS so that clientdomain.com (and www.clientdomain.com) point to the production server while beta.clientdomain.com points to your dev server (office IP). Then create a VirtualHost for beta.clientdomain.com that has a DocumentRoot of /path/to/dev/space and one for clientdomain.com that has a DocumentRoot of /path/to/live/space. I believe order is important if you have a wildcard, catch-all ServerAlias, since *.clientdomain.com would match beta.clientdomain.com if it wasn't first.
    Code:
    NameVirtualHost *
    
    <VirtualHost *>
      ServerName beta.clientdomain.com
      DocumentRoot /path/to/dev/space
      ...
    </VirtualHost>
    
    <VirtualHost *>
      ServerName clientdomain.com
      ServerAlias *.clientdomain.com
      DocumentRoot /path/to/prod/space
      ...
    </VirtualHost>
    Another approach is to use clientdomain.yourdomain.com.

    You can then use this same config file on both dev and production. Note, however, that Apache will probably complain about missing DocumentRoots on startup.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    Let's see if I understand this correctly. You have two servers, one is your dev/preview server located in your office and one is your production server located in a data center. You'd like to have one Apache config that's shared across both servers but that uses a different DocumentRoot based on whether you're in the office or not
    No, I'm a senior developer, I know how the web works, I'm not that stupid.

    But you're right in some respects.

    I develop locally for everything, and have two dedicated servers in the datacentre -stage and live.

    However, this particular client has caused us to purchase propitiatory software paid for on a per-server licence cost. To keep the costs down I want to have stage and live for this client on the production server (where we've installed the software)

    Being different servers, the IP of the stage and live servers are different, but if I put both on the live then the IP is the same.

    Before we got the stage server we used to put stage and live on the same dedicated server and use sub domains, exactly in the way you describe (although it's all managed through plesk)

    The problem for me now is that this obscure software the client requires reads the server name and bases business logic on that, so I as far as I can see I can't reliably test www.client.com on client.mycompany.com.

    The other issue is that the client's old site is also hosted on the live server...............

    ............Just had a thought.....

    I'll move client old site to stage and update DNS then in my hosts file override DNS to live for my testing, then switch DNS back again once new site is working
    Last edited by Northie; March 12th, 2012 at 07:45 AM.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1100
    No, I'm a senior developer ...
    Now how would I determine that from your post

    You could probably do this with proxying, too, but a DNS approach would probably be faster and easier since it's just for testing.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  8. #5
  9. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    Originally Posted by jharnois
    Originally Posted by me
    No, I'm a senior developer ...
    Now how would I determine that from your post
    I didn't expect anyone too....but nor did i expect anyone to think I was trying to split a configuration over multiple server locations !!!
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]

IMN logo majestic logo threadwatch logo seochat tools logo