Allow access to site via .htaccess / rewrite rules to certain countries only?

Crazy Serb

Well-Known Member
#1
Ok, since I can't use SetEnvIf parameters to do this, and was suggested to use rewrite rules to do so, I've tried this (to allow access only to US & Canadian visitors to the site):

Code:
RewriteEngine on
RewriteCond %{ENV:COUNTRY_CODE} !^(US|CA)$
RewriteRule ^(.*)$ - [F,L]
But that doesn't do anything...

Now, I see COUNTRY_CODE in my $_SERVER variables, so... am I referencing it wrong or something?
 

Crazy Serb

Well-Known Member
#3
Ugh, figured it out... as per https://docs.litespeedtech.com/lsws/cp/cpanel/geoip/#testing

"By design, you must use the GEOIP_ prefix for environment variables when using them in rewrite rules. This allows the rewrite engine to perform a GEOIP lookup. Customized environment variables that begin with another prefix, such as HTTP_ for example, only work with PHP code. They do not work with rewrite rules. "

I didn't use the default GEOIP_ prefixes... once I added that, it started working just fine.
 
Top