基于IP mod_rewrite的IP、mod_rewrite

2023-09-02 09:39:01 作者:独守空房丶为等伊人笑

我想实现的mod_rewrite把我的网站进入维持性。基本上,除了我们指定了一把所有IP将被转发到一个静态的HTML页面。

I'd like to implement mod_rewrite to put my site into maintance. Basically all ips 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 editting the htaccess file?

谢谢, 约什

推荐答案

您可以使用 REMOTE_ADDR在的RewriteCond 变量

RewriteCond %{REMOTE_ADDR} !^10.0.1.1$
RewriteRule ^ /maintenance.html

只要改变条件来匹配你想要的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.