本文介绍了需要基于自定义 http 标头的重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Cloudflare 正在向我们的服务器发送所有请求的标头 CF_IPCountry,其中包含发起请求的国家/地区代码.
Cloudflare is sending a header CF_IPCountry on all requests to our server, which contains the country code from which the request originated.
我们需要将所有来自新西兰 (CF_IPCountry = NZ) 的请求(永久地,包括 POST 请求)重定向到子域 nz.foo.co.nz,以便将其用作国内流量,而不是来自 cloudflare 的海外服务器.
We need to redirect (permanently, including POST requests) all requests coming from New Zealand (CF_IPCountry = NZ) to a subdomain nz.foo.co.nz so that it will be served as domestic traffic and not from cloudflare's servers overseas.
我需要什么条件和规则?
What condition and rule do I need?
推荐答案
尝试使用 %{HTTP:<headername>}
var:
RewriteCond %{HTTP:CF_IPCountry} ^NZ$ [NC]
RewriteRule ^(.*)$ http://nz.foo.co.nz/$1 [L,R=301]
这篇关于需要基于自定义 http 标头的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!