需要基于自定义http标头的重写规则 [英] Need a rewrite rule based on a custom http header

查看:95
本文介绍了需要基于自定义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标头的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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