The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
.htaccess: multiple document roots based on IP
Discuss .htaccess: multiple document roots based on IP in the Apache Development forum on Dev Shed. .htaccess: multiple document roots based on IP Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 29th, 2012, 09:26 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
|
.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!)
|

March 11th, 2012, 10:22 AM
|
 |
mod_dev_shed
|
|
Join Date: Sep 2002
Location: Atlanta, GA
|
|
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.
|

March 12th, 2012, 04:15 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
Quote: | 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 06:45 AM.
|

March 14th, 2012, 09:27 AM
|
 |
mod_dev_shed
|
|
Join Date: Sep 2002
Location: Atlanta, GA
|
|
Quote: | 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.
|

March 14th, 2012, 09:38 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
Quote: | Originally Posted by jharnois
Quote: | 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 !!!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|