How to geolocate an IP address in the .htaccess file

126 Views Asked by At

We are using a shared hosting server and deployed Yii 2 application on it. We would like to restrict users from accessing the application from certain countries and states using geo ip services.

Suppose a user trying to access the application has a specific IP address. If that IP address is from the allowed country then only the user should see the application otherwise 403 error message should be displayed.

We have the below code in the .htaccess file. Do we need to make some more changes in the .htaccess?

GeoIPEnable On

RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(US)$
RewriteRule (index).php$ - [F,L]

Thanks.

0

There are 0 best solutions below