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
[L开发者_StackOverflow中文版ANG_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
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.
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.
精彩评论