Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I've got this in httpd.conf:

<VirtualHost xx.xxx.xx.xxx>
    Options All +ExecCGI
    ServerAdmin hostmaster@thehost.com
    DocumentRoot /var/www/html/domain.com
    ServerName  dl.domain.org
    DirectoryIndex dlindex1.html
</VirtualHost>

... which is fine (what I need as the DirectoryIndex for our 'dl.domain.org' subdomain), but now I also need to alter that DirectoryIndex based on IP address, using .htaccess. Is this possible?

StackOverflow posts are telling me that I cannot set DirectoryIndex conditionally.. but instead have to use a RewriteRule. If that is true, OK, but what RewriteCond and RewriteRule? I am pretty noob in Apache, but anyway have tried many things, including (where the actual IPs are those of our 2 devs):

RewriteCond %{REMOTE_ADDR} ^111\.222\.333\.444$    [OR]
RewriteCond %{REMOTE_ADDR} ^555\.666\.777\.888$
RewriteCond %{SERVER_NAME} ^dl.domain.org
RewriteRule ^(.*)/$ $1/dlindex2.html

..or even just (as an absolute test):

RewriteCond %{REMOTE_ADDR} ^555\.666\.777\.888$
RewriteRule (.*)/dlindex1.html$ $1/dlindex2.html

But it seems that whatever I try it just serves up the DirectoryIndex dlindex1.html as per httpd.conf, as opposed to the dlindex2.html I want served up as the default page in that subdomain when a devs IP is calling.

Can any one point me to what I can do to get what I am after? i.e. this: ...to actually, or even just effectively, alter DirectoryIndex based on IP address, using .htaccess, on the fly?

share|improve this question
    
There are a few questions like this on StackOverflow. I would also search on ServerFault stackoverflow.com/questions/1599717/… –  Anagio Jul 27 '12 at 16:47
    
You mentioned to show a different index when a developers IP is accessing the site? Are you trying to create a development environment? –  Anagio Jul 27 '12 at 17:16
    
I did see that post.. and the accepted answer (stackoverflow.com/a/1599786/530006) gives an internal server error, so I do not see why it is accepted. Yes I am trying to have Apache serve up a development copy of the default page when my or another dev's IP (...the default page which is only the default page when coming in via a certain sub.domain. –  govinda Jul 27 '12 at 17:19
    
Why not htpassword the sub domain entirely, give your devs access and let them work on those files directly. You can rsync a complete copy of your server root. –  Anagio Jul 27 '12 at 17:24
1  
Well have a unique sub domain for dev's only. You'll have a live subdomain (production) then another sub domain (development), what CMS if any are you running? –  Anagio Jul 27 '12 at 17:49

1 Answer 1

up vote 2 down vote accepted

Use two subdomains one for the developers which you can make private and secure the other is your live production subdomain

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.