.htaccess 地理定位(不带 mod_geoip)

发布于 2024-10-26 18:27:26 字数 914 浏览 2 评论 0 原文

我正在尝试找出一种方法来执行以下操作:

将“lang token”包含到所有 .htaccess 重写网址中,如下所示:

RewriteRule ^/?$     _main_htaccess_handler?mod=homepage&lang=[LANG_STRING]
RewriteRule ^disclaimer\.htm?$     _main_htaccess_handler?mod=disclaimer&lang=[LANG_STRING]

...等等,对于所有网址

除意大利之外的所有国家/地区:

[LANG_STRING] = 'EN';

国家/地区意大利

[LANG_STRING] = 'IT';

现在,在寻找实现此目的的方法时,我找到了以下脚本:

http: //ipinfodb.com/country_query.php?country=IT&output=htaccess_allow

这将输出分配给某个国家/地区的 IP 列表,准确度为 99.5%。

我想将这些 IP 子网字符串“链接”到上面提到的 .htaccess 类型的方法。

不管怎样,我对在没有 mod_geoip 的情况下通过 .htaccess 进行地理定位有点困惑。

您认为我“创建”并上面提到的解决方案可以很好地工作吗?那么,搜索引擎呢?例如,Google Italy 能否正确找到意大利语页面? (这个问题适用于所有搜索引擎)

非常感谢

I'm trying to figure out a method to do the following:

Include a "lang token" into ALL .htaccess rewrited-urls, like this:

RewriteRule ^/?$     _main_htaccess_handler?mod=homepage&lang=[LANG_STRING]
RewriteRule ^disclaimer\.htm?$     _main_htaccess_handler?mod=disclaimer&lang=[LANG_STRING]

... and so on, for all the urls

All countries EXCEPT Italy:

[LANG_STRING] = 'EN';

Country ITALY

[LANG_STRING] = 'IT';

Now, searching for a method to accomplish this, I've found this script:

http://ipinfodb.com/country_query.php?country=IT&output=htaccess_allow

This will output a list of IPs allocated to a country, with a 99.5% accuracy.

I would like to "link" those IP subnet strings to the .htaccess type of approach mentioned above.

Anyway, I'm a little bit confused about geolocalization via .htaccess without the mod_geoip.

Do you think the solution I've "created" and mentioned above can work good? And then, what about search engines? Will, for example, Google Italy correctly find pages in Italian? (this question applies to all search engines)

Thank you very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你是年少的欢喜 2024-11-02 18:27:26

拥有巨大的 .htaccess 文件从来都不是一个好主意,因为在每次向给定网站发出请求之前都会解析该文件,从而导致性能损失。

Having a huge .htaccess file is never a good idea, since the file is parsed before every request to the given website, resulting in loss of performance.

dawn曙光 2024-11-02 18:27:26

在尝试了一些技术之后,我选择了一种混合技术:PHP + htaccess

我正在为那些将要解决这个问题的人编写它。

HTACCESS 配置:

RewriteRule    ^/?$    _builder.php?mod=language-redirect    [L,QSA]
RewriteRule    ^en/?$     _builder.php?mod=homepage&lang=en  [L,QSA]
RewriteRule    ^it/?$     _builder.php?mod=homepage&lang=it    [L,QSA]

_builder.php 代码(相对于意大利语和英语,可轻松转换以满足您的需求)

if ( ! isset ( $_GET['lang'] ) || ( $_GET['lang'] != 'en' && $_GET['lang'] != 'it' ) ) {
    // reaches here when someone accesses the / of the site. This piece of code outputs the correct geolocation language. If needed, you can also place an header redirect to the correct language-based homepage instead of defining the language
    $geoplugin = new geoPlugin();
    if ( $geoplugin -> countryCode == 'IT' ) define ( 'LANGUAGE', 'it' );
    else define ( 'LANGUAGE', 'en' );
}
else {
    if ( $_GET['lang'] == 'it' ) define ( 'LANGUAGE', 'it' );
    else define ( 'LANGUAGE', 'en' );
}

最后,可以通过 Google“PHP geoplugin”或以下网址访问 geoPlugin 类
http://www.geoplugin.com/webservices/php

请记住将语言设置器片段放入您的主构建器,因此脚本可以知道在页面上输出什么语言,即使 htaccess 没有传递该语言。

After having tried some techniques, I've opted for an hybrid one: PHP + htaccess

I'm writing it for the ones that will fly into this question.

HTACCESS CONFIGURATION:

RewriteRule    ^/?$    _builder.php?mod=language-redirect    [L,QSA]
RewriteRule    ^en/?$     _builder.php?mod=homepage&lang=en  [L,QSA]
RewriteRule    ^it/?$     _builder.php?mod=homepage&lang=it    [L,QSA]

_builder.php CODE ( relative to Italian and English Language, easily convertible to suit your needs )

if ( ! isset ( $_GET['lang'] ) || ( $_GET['lang'] != 'en' && $_GET['lang'] != 'it' ) ) {
    // reaches here when someone accesses the / of the site. This piece of code outputs the correct geolocation language. If needed, you can also place an header redirect to the correct language-based homepage instead of defining the language
    $geoplugin = new geoPlugin();
    if ( $geoplugin -> countryCode == 'IT' ) define ( 'LANGUAGE', 'it' );
    else define ( 'LANGUAGE', 'en' );
}
else {
    if ( $_GET['lang'] == 'it' ) define ( 'LANGUAGE', 'it' );
    else define ( 'LANGUAGE', 'en' );
}

Finally, the geoPlugin Class is reachable through Google "PHP geoplugin" or by this url:
http://www.geoplugin.com/webservices/php

Remember to place the language setter snippet into your main builder, so the script can know what language to output on the page, even if that wasn't passed by htaccess.

樱花坊 2024-11-02 18:27:26

我尝试获取美国 IP htaccsses 代码

code

Site1 senior188

Site2 senior188

Site3 senior188

site4 senior188

它正在工作,页面转到 403 ..但是我尝试用另一个IP国家/地区打开页面仍然显示403..它应该只适用于美国IP..

i try for the US IP htaccsses code

code

Site1 senior188

Site2 senior188

Site3 senior188

site4 senior188

it's working the page go to 403.. but i try open with another IP country the page still showed 403.. it should only for US IP..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文