// w-gregg.juneau.ak.us; July 2008; make webpage reload with canonical url.

// Insert in the HTML head, replacing with the page's canonical url:
//   <base href="http://example.co.uk/extensionless_page">
//   <script type="text/javascript" src="mkcanonical.js">//</script>
// Below:
//   Set alias array count to total hostnames including canonical hostname.
//   Set alias[0] to desired canonical hostname.
//   Set alias[1] to first alias hostname and add all known non-canonical hostnames.

// See w-gregg.juneau.ak.us/2008g25-canonical-url-javascript.htm.

var alias = new Array(2);
alias[0] = 'w-gregg.juneau.ak.us';
alias[1] = 'www.w-gregg.juneau.ak.us';
var basehref;
var baseget;
var hostname;
var i;
if (document.getElementsByTagName) {
    basehref = document.getElementsByTagName('base')[0].href;
    baseget = location.protocol + '//' + location.hostname + location.pathname;
    hostname = location.hostname.toLowerCase();
    for (i = 0; i < alias.length;i++) {
        if ((hostname === alias[i]) && (basehref !== baseget)) {
            location.replace(basehref + location.hash + location.search);
        }
    }
}
