conditional DirectoryIndex in .htaccess

旧时模样 提交于 2019-12-31 02:42:08

问题


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?


回答1:


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



回答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


来源:https://stackoverflow.com/questions/1599717/conditional-directoryindex-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!