$(document).ready(function() { var isHttps = SERVER_NAME.indexOf('https://') > -1; var subdomains = ['store', 'www', 'print', 'promo']; var currentSubdomain = ''; for (var i = 0; i <= subdomains.length - 1; i++) { if (SERVER_NAME.indexOf(subdomains[i] + '.') > -1) { currentSubdomain = subdomains[i]; break; } } var replaceSubdomains = []; for (var i = 0; i <= subdomains.length - 1; i++) { if (subdomains[i] === currentSubdomain) { continue; } replaceSubdomains.push(SERVER_NAME.replace(currentSubdomain + '.', subdomains[i] + '.')); } if (isHttps) { $('a[href*="http:"]').each(function() { if (isHttps) { if ($(this).attr('href').indexOf('http://') > -1) { $(this).attr('href', $(this).attr('href').replace('http://', 'https://')); } } }) } for (var i = 0; i <= replaceSubdomains.length - 1; i++) { $('a[href*="' + replaceSubdomains[i] + '"]').each(function() { $(this).attr('href', $(this).attr('href').replace(replaceSubdomains[i], SERVER_NAME)); }); } });