---
layout: null
title: 404 Redirector
permalink: /404.html
---

<script language="JavaScript">
var forwardingURL=window.location.pathname;
if (forwardingURL.charAt(forwardingURL.length - 1) != "/") forwardingURL += "/";
var gonnaFwd = false;
var newURL = "";
var baseURL = "";
var archive = false;
console.log(forwardingURL);

// .MD EXTENSION CHECK
if (forwardingURL.indexOf(".md") > -1)
{
  gonnaFwd = true;
  newURL = forwardingURL.replace(".md","");
} else {

  // DOCS ARCHIVE CHECK
{% for item in site.data.docsarchive.docker-compose %}
  if (forwardingURL == "/{{ item[0] }}/")
  {
    console.log("Found via Docker Compose file for Acrhive")
    gonnaFwd = true;
    archive = true;
    // make it so redirects cascade; first, use the base URL, then append path
    baseURL = "{{ site.url }}";
    newURL = forwardingURL;
  }{% endfor %}

if (archive==false) {
  // CSV CHECK
  {% for item in site.data.redirects %}
  var redirectVal = {{ item | jsonify }};
  if (forwardingURL == redirectVal.source)
  {
    console.log("Found via CSV @ ", redirectVal.source, redirectVal.destination);
    gonnaFwd = true;
    newURL = forwardingURL.replace(redirectVal.source,redirectVal.destination);
  }
{% endfor %}

  // PAGE ALIASES CHECK
{% for page in site.pages %}{% if page.aliases %}
  var aliases = {{ page.aliases | jsonify }};
  if( Object.prototype.toString.call( aliases ) === '[object Array]' ) {
    // aliases is an array, therefore, there are multiple aliases
    for (i=0; i< aliases.length; i++)
    {
      if (forwardingURL == aliases[i])
      {
        console.log("Found via Page Aliases on a multi-alias page @", "{{ page.url }}", aliases[i])
        gonnaFwd = true;
        newURL = "{{ page.url }}";
      }
    }
  } else {
    // only one alias for this page.
    if (forwardingURL == aliases)
    {
      console.log("Found via Page Aliases on a single-alias page @", forwardingURL.indexOf(aliases[i]), aliases[i])
      gonnaFwd = true;
      newURL = "{{ page.url }}";
    }
  }
{% endif %}{% endfor %}

} // end of check for .md
} // end of check for archive

if (gonnaFwd) {
  newURL = baseURL + newURL;
  console.log("Forwarding to: " + newURL);
  window.location.replace(newURL);
  window.location.href = newURL;
  document.write('<meta http-equiv="refresh" content="0; url=' + newURL + '">')
} else {
  window.location.replace("/sorry/#" + forwardingURL);
  window.location.href = "/sorry/#" + forwardingURL;
  document.write('<meta http-equiv="refresh" content="0; url=/sorry/#' + forwardingURL + '">')
}
</script>
