Server - Apache 2.4; Modules - mod_geoip, mod_rewrite.
I installed mod_geoip, set up .htaccess redirect from all pages of the site to one https://example.com/restricted/ for users from China and India.
Htaccess rule used # 1
RewriteEngine On GeoIPEnable On RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(CN|IN)$ RewriteRule ^(.*)$ https://example.com/restricted/$1 [L] As a result, citizens of China and India receive an error: ERR_TOO_MANY_REDIRECTS
looks like this:
www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:16 +0000] "GET / HTTP/1.1" 302 3942 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KH$ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:16 +0000] "GET /restricted/ HTTP/1.1" 302 664 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.$ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:16 +0000] "GET /restricted/restricted/ HTTP/1.1" 302 678 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebK$ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:16 +0000] "GET /restricted/restricted/restricted/ HTTP/1.1" 302 692 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) Ap$ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:16 +0000] "GET /restricted/restricted/restricted/restricted/ HTTP/1.1" 302 706 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; $ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:17 +0000] "GET /restricted/restricted/restricted/restricted/restricted/ HTTP/1.1" 302 720 "-" "Mozilla/5.0 (Windows NT 6.1; $ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:17 +0000] "GET /restricted/restricted/restricted/restricted/restricted/restricted/ HTTP/1.1" 302 734 "-" "Mozilla/5.0 (Windows N$ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:17 +0000] "GET /restricted/restricted/restricted/restricted/restricted/restricted/restricted/ HTTP/1.1" 302 748 "-" "Mozilla/5.0 (Wi$ www.example.com:443 40.108.122.138 - - [29/Jan/2019:21:41:17 +0000] "GET /restricted/restricted/restricted/restricted/restricted/restricted/restricted/restricted/ HTTP/1.1" etc.
Htaccess rule # 2
RewriteEngine On GeoIPEnable On RewriteCond %{REQUEST_URI} ^/$ [NC] RewriteCond %{ENV:GEOIP_COUNTRY_CODE} (CN|IN) [NC] RewriteRule .* https://example.com/restricted/ [R=302,L] As a result, citizens of China and India: go to example.com -> the coveted redirect to https://example.com/restricted/ - it works; the transition to example.com/about/ -> the coveted redirect to https://example.com/restricted/ - does not work.
Tell me, please, what is my mistake ?! How to set up a redirect from all pages to one for users from China and India?
Note: Htaccess is also present:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> Also in the settings sites-enabled / example.conf:
<VirtualHost *:80> ServerName www.example.com ServerAlias example.com ServerAdmin support@example.com RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule ^ https://example.com%{REQUEST_URI} [L,NE,R=301] </VirtualHost> <VirtualHost *:443> ServerName www.example.com ServerAlias example.com ServerAdmin support@example.com RewriteEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> Thank!
RewriteCond %{REQUEST_URI} ^/$ [NC]replace withRewriteCond %{REQUEST_URI} !^/restricted/$ [NC]- de_fragRewriteCond %{REQUEST_URI} ^/$ [NC] замените на RewriteCond %{REQUEST_URI} !^/restricted/$ [NC]is replaced,RewriteCond %{REQUEST_URI} ^/$ [NC] замените на RewriteCond %{REQUEST_URI} !^/restricted/$ [NC]in "htaccess rule # 2" - I get ERR_TOO_MANY_REDIRECTS. - Igor