Apache Geoip重定向到页面,带问号
我有一个与GeoIP重定向的绊脚石(Apache/2.4.6(Centos))。
Htaccess具有强制性指令(功能性所需的必要,更改可能会破坏整个站点),
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
因此当我添加.htaccess时,Geoip规则像
RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^DE$
RewriteRule ^/?index\.php$ http://de.example.com/info.html$1 [L]
它一样工作正常,但是当我想将类似的重定向设置为带有翻译的页面时,
RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^DE$
RewriteRule ^/?index\.php$ http://de.example.com/?lang=de$1 [L]
我的错误“重定向太多”。
在.htaccess中禁用geoip,然后直接转到 http://de.example.com/?lang=de - 一切都很好。
已经花了几个小时在语法上玩,但仍然无法遇到问题,所以要尝试任何想法!
I have a stumbling block with GeoIP redirect (Apache/2.4.6 (CentOS))
.htaccess has the mandatory directives (necessary for functionality, change can break the whole site)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
so when I add to .htaccess a GeoIP rule like
RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^DE$
RewriteRule ^/?index\.php$ http://de.example.com/info.html$1 [L]
it works fine, but when I want to setup a similar redirect to a page with translation
RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^DE$
RewriteRule ^/?index\.php$ http://de.example.com/?lang=de$1 [L]
I have error "too many redirects".
Disable GeoIP in .htaccess and go directly to http://de.example.com/?lang=de - all OK.
Already spent few hours playing around syntax but still can't catch what's wrong, so thx for any idea to try !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您很可能不想进行外部重定向,以将您的内部URL暴露于客户。您想要的(大概)是检测Geoip国家,并基于此添加一个具有相同国家代码的查询参数。您需要添加否定条件以停止重写,当时
lang =
查询参数已经存在。您可以在.htaccess中尝试此代码:
在测试此更改之前,请确保清除浏览器缓存。
Most likely you don't want to do an external redirect that exposes your internal URL to clients. All you want (presumably) is to detect GEOIP country and based on that add a query parameter with same country code. You need to add a negated condition to stop rewrite when
lang=
query parameter is already present.You may try this code in your .htaccess:
Make sure to clear your browser cache before testing this change.