Apache的重定向基于IP重写HTTP

Apache的重定向基于IP重写HTTP

本文介绍了Apache的重定向基于IP重写HTTP /的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向一个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?

推荐答案

下面就是做你想要什么重写配置的例子 - 把这个虚拟主机里面www.xxx.com您的服务器上:

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:

RewriteCond %{REMOTE_ADDR} 1.2.3.4
RewriteCond %{QUERY_STRING} !_DEBUG=1
#RewriteRule ^/(.*)$ /$1?_DEBUG=1 [QSA,R,L]
RewriteRule ^/(.*)$ /$1?_DEBUG=1 [QSA,L]

一对夫妇的注意事项:

A couple of notes:


  • 更改 1.2.3.4 到任何IP需要

  • 已经重新编写,包括 _DEBUG = 1 被重新第二个的RewriteCond prevents网址再次写入

  • 有实际重写规则两个版本;第一个版本(注释)实际执行重定向。如果你真的想HTTP客户端提交第二份请求到服务器,包括 _DEBUG = 1 参数使用此功能。缺点是,如果你结合GET和POST数据,这种方法是行不通的。

  • 的第二个版本的重写规则是我推荐你用...它不执行重定向。相反,它只是追加 _DEBUG = 1 参数来请求之前在内部Apache的HTTP请求处理。

  • Change 1.2.3.4 to whatever IP you need
  • The second RewriteCond prevents URLs already re-written to include _DEBUG=1 from being re-written again
  • There are two versions of the actual RewriteRule; 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.
  • The second version of the 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.

这篇关于Apache的重定向基于IP重写HTTP /的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 10:32