问题描述
是否可以根据 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!