Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a rewrite rule based on a custom http header

Cloudflare is sending a header CF_IPCountry on all requests to our server, which contains the country code from which the request originated.

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?

like image 709
Richard Grevers Avatar asked Feb 03 '26 02:02

Richard Grevers


1 Answers

Try using the %{HTTP:<headername>} var:

RewriteCond %{HTTP:CF_IPCountry} ^NZ$ [NC]
RewriteRule ^(.*)$ http://nz.foo.co.nz/$1 [L,R=301]
like image 133
Jon Lin Avatar answered Feb 05 '26 18:02

Jon Lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!