<system.webServer> <rewrite> <rules> <rule name="栾川登录页" stopProcessing="true"> <match url="v2/guest/$" /> <conditions> <add input="{HTTP_HOST}" pattern="^e\.djlc\.gov\.cn$" /> </conditions> <action type="Rewrite" url="v2/subsite/luanchuan/index.html" /> </rule> <rule name="西工登录页" stopProcessing="true"> <match url="v2/guest/$" /> <conditions> <add input="{HTTP_HOST}" pattern="^e\.xgdjw\.cn$" /> </conditions> <action type="Rewrite" url="v2/subsite/xigong/index.html" /> </rule> </rules> </rewrite> </system.webServer>
以上代码用途说明:
这个站有三个主机头 e.lydjw.gov.cn、e.xgjdw.cn、e.djlc.gov.cn,要根据三个主机头分别显示各自的登录页。
e.lydjw.gov.cn 的登录页: /v2/guest/index.html
e.xgdjw.cn 的登录页: /v2/subsite/xigong/index.html
e.djlc.gov.cn 的登录页: /v2/subsite/xigong/index.html
全部主机头同一个登录页: /v2/guest/
登录地址:
https://e.lydjw.gov.cn/v2/guest/ –> 加载 /v2/guest/index.html
https://e.djlc.gov.cn/v2/guest/ –> 加载 /v2/subsite/xigong/index.html
https://e.xgdjw.cn/v2/guest/ –> 加载 /v2/subsite/xigong/index.html
<完>
// 重定向到 https 201704101746 (function() { var protocol = window.location.protocol; if ('https:' != protocol) { var exceptions = [ // 正则式例外:192.和127.开头的主机名及localhost /^123\..*/, /^192\..*/, /^127\..*/, /^localhost/ ]; var hostname = window.location.hostname; var jump = true; for (var x in exceptions) { var reg = exceptions[x]; var pass = reg.test(hostname); if (true == pass) { // 只要主机名符合一项例外规则就不跳转 jump = false; break; } } if (true == jump) { var search = window.location.search; var hash = window.location.hash; var port = window.location.port; var pathname = window.location.pathname; var url = window.location.href; port = ("80" == port || "" == port) ? "" : ":" + port; url = 'https://' + hostname + port + pathname + search + hash; // console.log(url); console.log('正在从 http 转到 https ...'); window.location.href = url; } } })(); // 原IP:端口访问时转域名 (function () { var from = window.location.host; var to = 'https://e.lydjw.gov.cn/'; if ('123.56.204.211:8001' == from) { console.log('正在从 '+from+' 转到 '+to+' ...'); var search = window.location.search; var hash = window.location.hash; var pathname = window.location.pathname; to = to + pathname + search + hash; window.location.href = to; } })(); // End