[英]nginx: redirect mobile requests to /mobile/$uri
I am trying to setup my nginx to redirect all the requests from mobile devices to /mobile/$uri i came up with this solution but it doesn't seem to work. 我正在尝试设置我的nginx将所有来自移动设备的请求重定向到/ mobile / $ uri我想出了这个解决方案,但它似乎不起作用。 Is it a syntax problem or a misunderstanding of the whole redirecting concept.
这是一个语法问题还是对整个重定向概念的误解。
if ($http_user_agent ~* '(iPhone|iPod|android|blackberry)') {
rewrite ^(.*) http://xxxx.org/mobile/$1 permanent;
}
When i use my android phone i am getting something like xxx.org/mobile/mobile/mobile/mobile.... 当我使用我的Android手机时,我得到像xxx.org/mobile/mobile/mobile/mobile ....
Any ideas?Any suggestions? 任何想法?有什么建议吗?
You should use different locations: 您应该使用不同的位置:
location / {
if ($http_user_agent ~* '(iPhone|iPod|android|blackberry)') {
return 301 /mobile$request_uri;
}
}
location /mobile/ {
}
btw, http://nginx.org/r/return 顺便说一句, http://nginx.org/r/return
#initliaze mobile
set $mobile "";
if ($request_uri !~* "^/mobile.*" ){
set $mobile Y;
}
if ($http_user_agent ~* (iPhone|iPod|android|blackberry) ) {
set $mobile "${mobile}E";
}
if ( $http_referer !~* "xxx\.org" ){
set $mobile "${mobile}S";
}
if ( $host ~* "xxx\.org" ){
set $mobile "${mobile}S";
}
if ($mobile = YESS){
rewrite ^ $scheme://$host/mobile$request_uri ;
}
使用http://detectmobilebrowsers.com/它包含所有Web服务器和客户端/服务器端语言的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.