htaccess规则将国家参数添加到带有Cloudflare地理位置的URL中。

问题描述 投票:0回答:1

在我的编码工作中,我广泛地使用了stackoverflow,感谢你们提供了这样一个知识的源泉。

我想实现一个mod_rewritehtaccess规则,将访问者的国家作为参数加入到 任何 URL: 如果 国家与AT不同。地理定位是通过Cloudflare完成的。

就像。来自CH的游客访问 https:/www.example.comblabla => https:/www.example.comblabla国家=CH

我对htaccess重写不是太精通,最后出现无限循环服务器错误。我相信这是一个正确的 重写规则 我缺少的部分。这是我的代码。

SetEnvIf CF-IPCountry "(.*)$" Country=$1
RewriteCond %{ENV:Country} !AT
RewriteRule ^(.*)$ $1?country=%{ENV:Country} [R,L,QSA]

任何帮助都将是非常感激的。

.htaccess mod-rewrite geolocation cloudflare
1个回答
0
投票

谢谢你为我指出了正确的方向.对于任何面临同样问题的人,解决方案是。

SetEnvIf CF-IPCountry "(.*)$" Country=$1
RewriteCond %{ENV:Country} !AT
RewriteCond %{QUERY_STRING} !country
RewriteRule ^(.*)$ $1?country=int [R=308,L,QSA]

我没有找到一种方法来添加... ... 特定 国家代码,因为我无法在 "RewriteRule "中引用ENV:Country,但是对于所有非AT的国家来说,"int "对我来说很好用。

© www.soinside.com 2019 - 2024. All rights reserved.