Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
litespeed_wiki:cache:common:geoip-support [2019/01/08 19:30]
Lisa Clarke [''GeoIPDBFile'' directive is for Apache, not LSWS]
litespeed_wiki:cache:common:geoip-support [2019/01/08 19:39]
Lisa Clarke [Please clarify what do you mean ''GeoIP not working'']
Line 123: Line 123:
 In Apache, you can use ''​GeoIPDBFile''​ directive to define the database, however it cannot be used for LiteSpeed. You should follow the beginning steps in this wiki to define the database path from LSWS Web Admin Console or the LSWS configuration file directly. ​ In Apache, you can use ''​GeoIPDBFile''​ directive to define the database, however it cannot be used for LiteSpeed. You should follow the beginning steps in this wiki to define the database path from LSWS Web Admin Console or the LSWS configuration file directly. ​
  
-==== Why infinite redirect for my GeoIP rewrite ​Rules ====+==== GeoIP Rewrite ​Rules Infinite Loop ====
  
-A user would like to setup GeoIP rules to direct traffic to main domain'​s subfolder based on IPs. The following rules have been set in .htaccess, however, it seems to come to redirect loop hence claimed GeoIP was not working properly+A user would like to set up GeoIP rules to direct traffic to the main domain'​s subfolder based on IP. The following rules have been set in .htaccess, however, it seems to cause a redirect loop.
   RewriteEngine on   RewriteEngine on
   RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} ^US$   RewriteCond %{ENV:​GEOIP_COUNTRY_CODE} ^US$
Line 134: Line 134:
   RewriteRule ^(.*)$ https://​www.example.com/​my/​$1 [R,L]   RewriteRule ^(.*)$ https://​www.example.com/​my/​$1 [R,L]
  
-If it came to a redirect loop, it means GeoIP module ​was actually ​working. ​How the redirect loop occurs? While for such subfolder redirect, you might need to be more careful. ​The reason you get a redirect error, is because the rules will be evaluated again after the redirect ​has been performed, ​so if you access ''/''​ it gets redirected to e.g. ''/​us'',​ then on ''/​us'',​ it will be asked to redirect again to ''/​us''​ - and you end up with a loop. The fix is to add an additional condition to prevent this, such as ''​RewriteCond %{REQUEST_URI} !^/​us[NA]''​. ​So what it doesis to only redirect to /us if country code from the GeoIP matches US and the request URI doesn'​t start with /us.+The redirect loop actually indicates the the GeoIP module ​is working. ​ 
 + 
 +The redirect error happens ​because the rules are evaluated again //after// the redirect ​is performed. So, if you access ''/''​, and it gets redirected to e.g. ''/​us'',​ then on ''/​us'',​ it will be asked to redirect ​//again// to ''/​us''​ - and you end up with a loop. The fix is to add an additional condition to prevent this, such as ''​RewriteCond %{REQUEST_URI} !^/​us[NA]''​. ​This wayyou only redirect to ''​/us'' ​if the country code from GeoIP matches US //and// the request URI doesn'​t ​already ​start with ''​/us''​.
  
 The final rules should be: The final rules should be:
Line 149: Line 151:
   RewriteRule ^(.*)$ https://​www.example.com/​my/​$1 [R,L]   RewriteRule ^(.*)$ https://​www.example.com/​my/​$1 [R,L]
   ​   ​
-==== Please clarify what do you mean ''​GeoIP not working''​==== +==== Be more specific than "GeoIP not working"==== 
-Quite often we received ​report claiming ​''​GeoIP not working''​It is a little ​vague/confused that if ''​GeoIP module ​not working''​or ''​GeoIP rewrite rules do not work as expected''​You 'd better ​to clarify ​the above first before logging any ticket.+Quite often we receive a report claiming ​that "GeoIP is not working""​This is too vague. Is the GeoIP module ​note working? ​Or are the GeoIP rewrite rules not working ​as expected? ​It's best to clarify before logging any ticket.
  
-''​GeoIP module ​not working'' ​can be easily verified through the following (change the country code ''​US''​ to your country code accordingly):​+Whether the GeoIP module ​is working can be easily verified through the following (change the country code ''​US''​ to your country code accordingly):​
  
 <​code>​ <​code>​
Line 162: Line 164:
 </​code>​ </​code>​
   ​   ​
-If it returns 404, then it means GeoIP module is actually working. ​+If it returns 404, then it means the GeoIP module is actually working. ​
   ​   ​
-''​GeoIP rewrite rules do not work as expected" could be more complicated. You will need to check the rules to see any bug there, ​such as redirect loop. When needed, you can log a ticket with us with the rules set not working as expected and more detailed test example for us to take a further look. +GeoIP rewrite rules that do not work as expected ​may be more complicated. You will need to check the rules to look for issues ​such as redirect loop. When needed, you can log a ticket with us. Let us know the rules set is not working as expectedand provide a more detailed test example for us to take a further look. 
  • Admin
  • Last modified: 2020/11/14 15:24
  • by Lisa Clarke