3

Is it possible to make the DirectoryIndex value in a .htaccess file conditional based on IP, so that - for example - my IP see's DirectoryIndex as index.html and everyone else sees DirectoryIndex as index.php?

Is there a solution other than mod_rewrite?

robjmills
  • 18,438
  • 15
  • 77
  • 121

2 Answers2

4

As far as I know, there is no conditional for DirectoryIndex. You could simulate that with a mod_rewrite directive like this one:

RewriteCond %{REMOTE_ADDR} your_ip
RewriteCond -d
RewriteRule (.*)/$ $1/index.html

If you want to exclude other visitors of the site from viewing index.html then also use

RewriteCond %{REMOTE_ADDR} !your_ip
RewriteRule (.*)/index.html$ $1/index.php
Residuum
  • 11,878
  • 7
  • 40
  • 70
  • yeah, that was going to be my fallback if it wasnt possible. if no-one else has another solution i'll accept this. – robjmills Oct 21 '09 at 10:01
2

Using the provided information I beleive the following is what you need:

RewriteCond %{REMOTE_ADDR} ^your_ip$
RewriteRule (.*)/$ $1/index.php

RewriteCond %{REMOTE_ADDR} !^your_ip$
RewriteRule index.php$ index.html

So that only your IP can see index.php and everybody else will see index.html

or possibly:

DirectoryIndex index.html

RewriteCond %{REMOTE_ADDR} ^your\.ip\.000\.000$
RewriteRule ^index.html$ index.php
Lizard
  • 43,732
  • 39
  • 106
  • 167
  • This is working for me, but how can I add muliple ip's? DirectoryIndex index.html RewriteCond %{REMOTE_ADDR} ^your\.ip\.000\.000$ RewriteRule ^index.html$ index.php thanks – EricP Aug 27 '10 at 13:43