有工作htaccess,阻止特定国家和/或语言,
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^NL$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^BY$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^UA$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RU$ [NC,OR]
RewriteCond %{HTTP:Accept-Language} (nl) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (be) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (uk) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (ru) [NC]
RewriteRule ^(.*)$ cap.html [L]
但我需要访问特定路线,例如api.html到任何国家/地区/语言。 我尝试添加异常
RewriteCond %{REQUEST_URI} !^/api\.html
但它不起作用,我已经尝试了数百个条件但放弃了6个小时,请告诉我我做错了什么。
RewriteEngine On
# Exclude countries, forbidden by law
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^NL$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^BY$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^UA$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RU$ [NC,OR]
RewriteCond %{HTTP:Accept-Language} (nl) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (be) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (uk) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (ru) [NC]
RewriteCond %{REQUEST_URI} !^/api\.html
RewriteRule ^(.*)$ cap.html [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteRule ^.*$ index.php [L]
答案 0 :(得分:0)
尝试:
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^NL$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^BY$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^UA$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^RU$ [NC,OR]
RewriteCond %{HTTP:Accept-Language} (nl) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (be) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (uk) [NC,OR]
RewriteCond %{HTTP:Accept-Language} (ru) [NC]
#rewrite everything to "cap.html" except "api.html"
RewriteRule ^((?!api\.html).*)$ cap.html [L]
答案 1 :(得分:0)
您当前的代码似乎合乎逻辑,但您可以尝试将条件合并在一起,并将最后一个条件移到顶部:
RewriteCond %{REQUEST_URI} !^/api\.html [NC]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(?:NL|BY|UA|RU)$ [NC,OR]
RewriteCond %{HTTP:Accept-Language} (?:nl|be|uk|ru) [NC]
RewriteRule ^ cap.html [L]
答案 2 :(得分:0)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(?:NL|BY|UA|RU)$ [NC,OR]
RewriteCond %{HTTP:Accept-Language} (?:nl|be|uk|ru) [NC]
RewriteRule ^ cap.html [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteRule ^.*$ index.php [L]