Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
themeRDark
linenumberstrue
// REDIRECTS
if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) {
  // Easily Change status code and base url for testing here:
  $host = 'my.kettering.edu';
  $http_code = 'HTTP/1.0 303 See Other';
  $redirect = FALSE;

  // Add URLS to skip this AKA 1-1:
  $skip = array(
    '/admissions',
  );

  // Set this to a var so we don't mess with doing all this fun stuff below.
  $uri = $_SERVER['REQUEST_URI'];

  // Redirect to legacy site based on set patterns, etc.
  if (!in_array($uri, $skip)) {
    // Wildcard Redirects.
    $wildcard = array(
      'academics',
      'alumni-donors',
      'current-students',
      'downloads',
      'emergency',
      'faculty-staff',
      'faculty',
      'ferpa',
      'it',
      'news',
      'office-administration',
      'offices-administration',
      'research',
    );

    // One to One from www.kettering.edyuedu to my.kettering.edyedu
    $onetoone = array(
      '/archives',
      '/asc',
      '/Atwood',
      '/brand',
      '/businessOffice',
      '/career-services',
      '/cetl',
      '/commencement',
      '/communityservice',
      '/currentstudents',
      '/deans-list',
      '/dining',
      '/emergency',
      '/employee-information',
      '/events',
      '/ferpa',
      '/financialaid',
      '/financialAid',
      '/first',
      '/flintwater',
      '/get-word-out',
      '/give',
      '/greeklife',
      '/hr',
      '/keepmekettering',
      '/library',
      '/marcomm',
      '/nbs',
      '/Oldschool',
      '/phonathon',
      '/regbell',
      '/registrar',
      '/sharing-memories-professor-bell',
      '/studentlife',
      '/trustee-rsvp',
      '/water',
      '/wellness-center',
    );

    // String Match Redirects.
    $string_checks = array(
      '/about/accreditation-and-assessment',
      '/sites/default/files/resource-file-download',
    );

    // Time to make the magic happen.
    $uri_check = explode('/', $_SERVER['REQUEST_URI']);

    // Check for Wildcard Redirect || 1 to 1 www to my first.
    if ((isset($uri_check[1]) && in_array($uri_check[1], $wildcard)) ||
        (in_array($uri, $onetoone))) {
      $redirect = TRUE;
    }
    // Redirect to specific legacy pages or paths.
    elseif (isset($uri_check[1])) {
      // Change the URI or HOST based of the base uri path.
      switch ($uri_check[1]) {
        case 'alumni':
          $redirect = TRUE;
          $uri = '/alumni-donors/get-involved';
          break;
        case 'directory':
          $redirect = TRUE;
          $uri = '/faculty-staff/directory';
          break;
        case 'giving':
          $redirect = TRUE;
          $uri = '/give';
          break;
        case 'aanouncements':
          $redirect = TRUE;
          $uri = '/announcements';
          break;
        case 'partnerships':
          $redirect = TRUE;
          $uri = '/alumni-donors';
          break;
        case '~':
          $redirect = TRUE;
          $host = 'paws.kettering.edu';
          break;
        case 'ug-admitted':
          $redirect = TRUE;
          $host = 'accepted.kettering.edu';
          break;
        case 'iamabulldog':
          $redirect = TRUE;
          $host = 'accepted.kettering.edu';
          break;
        case 'admissions':
          // This was the easiest way to handle all the admissions ones.
          $redirect = TRUE;
          unset($uri_check[1]);
          $uri = implode('/', $uri_check);
          $host = 'www.kettering.edu';
          break;
      }
      // Check for string paths.
      if (!$redirect) {
        foreach ($string_checks as $string_check) {
          if (strpos($uri, $string_check) !== FALSE) {
            $redirect = TRUE;
          }
        }
      }
    }
  }
  // If true above, lets have some fun redirects happen!
  if ($redirect) {
    header($http_code);
    header('Location: https://'. $host . $uri);
    exit();
  }
  else {
    // Regular redirects to current site.
    $old = array(
      'm.kettering.edu',
      'admissions.kettering.edu',
    );

    if ($_SERVER['PANTHEON_ENVIRONMENT'] === 'live' && $_SERVER['HTTPS'] === 'OFF') {
      if (!isset($_SERVER['HTTP_X_SSL']) ||
         (isset($_SERVER['HTTP_X_SSL']) && $_SERVER['HTTP_X_SSL'] != 'ON')) {
        header($header);
        header('Location: https://www.kettering.edu' . $_SERVER['REQUEST_URI']);
        exit();
      }
    }
    elseif ($_SERVER['PANTHEON_ENVIRONMENT'] === 'live' && in_array($_SERVER['HTTP_HOST'], $old)) {
      header($header);
      header('Location: https://www.kettering.edu'. $_SERVER['REQUEST_URI']);
      exit();
    }
    elseif ($_SERVER['HTTP_HOST'] == 'my.kettering.edu') {
      $newurl = 'https://www.kettering.edu/faculty-staff'. $_SERVER['REQUEST_URI'];
      header($header);
      header("Location: $newurl");
      exit();
    }
  }
}

...