更改站点前缀

以下示例控制器文件定义 preInitRendering 函数,以允许基于多个前缀传送站点。

注:

要利用此示例,必须配置 CDN 或其他代理以响应定义的前缀。此外,如果函数中定义的附加前缀都不匹配浏览器 URL,则将使用默认行为。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1">
<script type="text/javascript">
var SCS = { sitePrefix: '/SampleSite/' };
 
SCS.preInitRendering = function() {
     // List additional site prefixes here. All sitePrefix values MUST start and end with a '/' character.
     var additionalSitePrefixes = [
           '/corporate/intranet/SampleSite/',
           '/marketing/preflight/',
           '/qa/'
     ];
 
     // Determine if the actual browser URL matches one of the additional site prefixes
     var pageUrl = decodeURI(window.location.pathname);
     var i, prefix;
     for (i = 0; i < additionalSitePrefixes.length; i++) {
           prefix = additionalSitePrefixes[i];
           if (pageUrl.startsWith(prefix) || (pageUrl === prefix.slice(0, -1))) {
                // If we find a match, set the global site prefix variable
                SCS.sitePrefix = prefix;
                break;
           }
     }
};
</script>
<script src="/SampleSite/_sitesclouddelivery/renderer/controller.js"></script>
</head>
<body id="scsControllerBody"><noscript>This site requires JavaScript to be enabled.</noscript>
<img id="scsWaitImage" style="display: none; margin-top: 5%; margin-left: auto; margin-right: auto;" src="data:image/png;base64,..." />
</body></html>