使用 .htaccess - 浏览器检测语言将子域重定向到同一子域中的文件夹
Redirect A subdomain To A folder in the same Subdomain using .htaccess - Browser detection language
我需要创建一个条件重定向(浏览器语言)并为 apache 重写以完成以下任务
将子域重定向到同一子域的文件夹,即
subdomain.domain.com redirects to subdomain.domain.com/es (if the browser language is setup on spanish, es or es-es)
subdomain.domain.com redirects to subdomain.domain.com/en (if the browser language is setup on english, en or en-us)
解决方案是
#Allow rewrite
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com [NC]
#For spanish redirect
RewriteCond %{REQUEST_URI} !^/es [NC]
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^(.*)$ http://subdomain.domain.com/es/ [L,R=301]
#For english redirect
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^(.*)$ http://subdomain.domain.com/en/ [L,R=301]
但是,如果我在 URL 栏上打字,例如
subdomain.domain.com/badurl (the badurl folder dont exist)
浏览器转到:
http://subdomain.domain.com/es/404.shtml
并说 "This webpage has a redirect loop"
我该如何解决
谢谢
使用 REQUEST_URI
代替 THE_REQUEST
。
RewriteCond %{REQUEST_URI} !^/es [NC]
我需要创建一个条件重定向(浏览器语言)并为 apache 重写以完成以下任务
将子域重定向到同一子域的文件夹,即
subdomain.domain.com redirects to subdomain.domain.com/es (if the browser language is setup on spanish, es or es-es)
subdomain.domain.com redirects to subdomain.domain.com/en (if the browser language is setup on english, en or en-us)
解决方案是
#Allow rewrite
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com [NC]
#For spanish redirect
RewriteCond %{REQUEST_URI} !^/es [NC]
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule ^(.*)$ http://subdomain.domain.com/es/ [L,R=301]
#For english redirect
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^(.*)$ http://subdomain.domain.com/en/ [L,R=301]
但是,如果我在 URL 栏上打字,例如
subdomain.domain.com/badurl (the badurl folder dont exist)
浏览器转到:
http://subdomain.domain.com/es/404.shtml
并说 "This webpage has a redirect loop"
我该如何解决
谢谢
使用 REQUEST_URI
代替 THE_REQUEST
。
RewriteCond %{REQUEST_URI} !^/es [NC]