.htaccess 中的条件 DirectoryIndex [英] conditional DirectoryIndex in .htaccess

查看:20
本文介绍了.htaccess 中的条件 DirectoryIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据 IP 使 .htaccess 文件中的 DirectoryIndex 值有条件,这样 - 例如 - 我的 IP 将 DirectoryIndex 视为 index.html 和其他人都将 DirectoryIndex 视为 index.php?

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?

除了mod_rewrite还有其他解决办法吗?

Is there a solution other than mod_rewrite?

推荐答案

据我所知,DirectoryIndex 没有条件.您可以使用类似这样的 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

如果您想排除该网站的其他访问者查看 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

这篇关于.htaccess 中的条件 DirectoryIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆