【发布时间】:2026-01-06 20:25:01
【问题描述】:
我有简单的代码来检查我的旧网站上的用户是否使用移动设备。如果使用,则使用变量重定向到新站点和移动版本。但同时我想检查用户是否是桌面并重定向到其他站点。
我的代码是:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
RewriteCond %{HTTP_HOST} !^m\.
RewriteCond %{HTTP:Cookie} !\mobile=0(;|$)
RewriteRule ^(.*)$ https://m.somesite.com/$1 [R=301,L]
这是可行的,但是如果用户是桌面,我可以在哪里放置带有变量的特殊重定向?
RewriteRule ^(.*)$ https://desktop.othersomesite.com/$1 [R=301,L]
类似的东西
<?php
...
if ($mobile = 1) {
header('Location: https://m.somesite.com/$1');
}
elseif ($mobile = 0) {
header('Location: https://desktop.othersomesite.com/$1');;
}
?>
谢谢:)
【问题讨论】: