开发者

conditional DirectoryIndex in .htaccess

Is it possible to make the DirectoryIndex value in a .hta开发者_开发技巧ccess 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?


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜