Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess使用Cloudflare位置重定向_Apache_.htaccess_Redirect_Geolocation_Cloudflare - Fatal编程技术网

Apache .htaccess使用Cloudflare位置重定向

Apache .htaccess使用Cloudflare位置重定向,apache,.htaccess,redirect,geolocation,cloudflare,Apache,.htaccess,Redirect,Geolocation,Cloudflare,我真的很难根据cloud flare国家代码将重定向放到我的.htaccess文件中。我要么收到“太多重定向错误”,要么使用整个站点的示例收到500个内部错误 我目前有: Options +FollowSymLinks RewriteEngine on SetEnvIf CF-IPCountry "(.*)$" Country=$1 RewriteCond %{ENV:Country} GB RewriteRule ^(.*)$ http://example.com/$1 [R,L] 因此

我真的很难根据cloud flare国家代码将重定向放到我的.htaccess文件中。我要么收到“太多重定向错误”,要么使用整个站点的示例收到500个内部错误

我目前有:

Options +FollowSymLinks
RewriteEngine on

SetEnvIf CF-IPCountry "(.*)$" Country=$1

RewriteCond %{ENV:Country} GB
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
因此,我需要将默认域设置为

但是,如果国家/地区代码GB来自cloudflare,例如,我需要将其重定向到:

以我对.htaccess的有限了解,这可能吗?

请尝试:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP:CF-IPCountry} ^GB$
RewriteCond %{REQUEST_URI} !(?:gif|png|jpg|jpeg|css)$ [NC]
RewriteRule !^gb/ /gb%{REQUEST_URI} [NC,NE,R,L]
重定向
http://example.com/test
http://example.com/gb/test
当请求来自
CF IPCountry=GB
的用户,而该用户尚未使用与
/GB/

的链接时,请尝试:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP:CF-IPCountry} ^GB$
RewriteCond %{REQUEST_URI} !(?:gif|png|jpg|jpeg|css)$ [NC]
RewriteRule !^gb/ /gb%{REQUEST_URI} [NC,NE,R,L]

重定向
http://example.com/test
http://example.com/gb/test
当请求来自
CF IPCountry=GB
的用户,而该用户尚未使用
/GB/

的链接时,这实际上是按预期工作的,但是,它破坏了我的所有资源(图像/css文件等)我认为它也在重定向这些请求。有没有一种方法可以避免这种情况,而不必在子文件夹中复制所有内容?我添加了一条规则,以避免对图像或css文件进行重写。该代码有效,但。。。如果我想添加更多国家以重定向到同一url,该怎么办?这是可能的(例如墨西哥和西班牙重定向到mydomain.com/es/和最后一个问题,它是否可能,所以如果它是主页,它只是重定向?谢谢你可以使用
!^(gb | mx | sp)//gb%{REQUEST_URI}[NC,NE,R,L]
为主页
重写规则$/gb/[R,L]
Hi,这实际上正如预期的那样工作,但是它破坏了我的所有资源(图像/css文件等)我认为它也在重定向这些请求。有没有一种方法可以避免这种情况,而不必在子文件夹中复制所有内容?我添加了一条规则,以避免重写图像或css文件。该代码起作用了,但是…如果我想添加更多的国家以重定向到同一url呢?有可能吗(例如,墨西哥和西班牙重定向到mydomain.com/es/还有最后一个问题,它是否可以重定向到主页?谢谢你可以使用
!^(gb | mx | sp)//gb%{REQUEST_URI}[NC,NE,R,L]
主页
重写规则^$/gb/[R,L]