基于ip的mod_rewrite [英] mod_rewrite based on ip

查看:23
本文介绍了基于ip的mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实施 mod_rewrite 来维护我的网站.基本上除了我们指定的少数 IP 地址之外的所有 IP 地址都会被转发到静态 html 页面.

I'd like to implement mod_rewrite to put my site into maintenance. Basically all IP addresses except a handful we specify would be forwarded to a static html page.

请有人帮忙制定这条规则.还有没有办法在不编辑 htaccess 文件的情况下轻松打开和关闭它?

Please can someone help with this rule. Also is there a way to turn this on and off easily without editing the htaccess file?

推荐答案

您可以使用 REMOTE_ADDR 变量

RewriteCond %{REMOTE_ADDR} !^10\.0\.1\.1$
RewriteRule ^ /maintenance.html

只需更改条件以匹配您想要的 IP,对于多个 IP,您可以使用 ^(ip1|ip2|...|ipn)$.

Just change the condition to match the IPs you want, for more than one you can use ^(ip1|ip2|...|ipn)$.

关于如何在不更改 .htaccess 文件的情况下禁用维护模式,我认为编写一个删除它或以其他方式修改它的程序是不可能的,一个简单的方法是重命名它.

About how to disable the maintenance mode without changing the .htaccess file I think that's not possible short of writing a program that would delete it or otherwise modify it, an easy one would be to rename it.

这篇关于基于ip的mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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