apache http 基于 ip 重写/重定向
我想将一个ip重定向到我网站的另一个视图,例如,我希望来自ip x的访问者看到
www.xxx.com?_DEBUG=1
当所有其他访问者看到正常的 www.xxx.com 时, 我该如何在 apache 配置文件中执行此操作,使用哪些指令?
I want to redirect an ip to another view of my website, for example, I want the visitor from ip x to see
www.xxx.com?_DEBUG=1
while all other visitors see the normal www.xxx.com,
how would I do this in apache config file, what directives are used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是一个重写配置的示例,可以执行您想要的操作 - 将其放入服务器上 www.xxx.com 的虚拟主机中:
一些注意事项:
1.2.3.4
更改为您想要的任何 IP需要RewriteCond
防止已重写以包含_DEBUG=1
的 URL 再次被重写RewriteRule
有两个版本;第一个版本(已注释掉)实际上执行重定向。如果您确实希望 HTTP 客户端向服务器提交第二个请求(包括_DEBUG=1
参数),请使用此选项。缺点是,如果您将 GET 和 POST 数据结合起来,此方法将不起作用。RewriteRule
...它不执行重定向。相反,它只是在处理请求之前在 Apache 内部将_DEBUG=1
参数附加到 HTTP 请求。Here is an example of a rewrite configuration to do what you want - put this inside the virtual host for www.xxx.com on your server:
A couple of notes:
1.2.3.4
to whatever IP you needRewriteCond
prevents URLs already re-written to include_DEBUG=1
from being re-written againRewriteRule
; the first version (commented out) actually performs a redirect. Use this if you actually want the HTTP client to submit a second request to the server including the_DEBUG=1
argument. The downside is that if you're combining GET and POST data, this method will not work.RewriteRule
is what I recommend you use...it doesn't perform a redirect. Instead it just appends the_DEBUG=1
parameter to the HTTP request internally in Apache before the request is handled.