From 76394ed7a159577b002c81244f63c9e7bd339237 Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Wed, 7 Dec 2011 18:01:47 +0000
Subject: [PATCH] [gh-260] Merging from testing into staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1342 20a16fea-79d4-4915-8869-1ea9d5ebf173
---
 includes/unl_bootstrap.inc | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/includes/unl_bootstrap.inc b/includes/unl_bootstrap.inc
index 9a3f394db..d8f3b15f4 100644
--- a/includes/unl_bootstrap.inc
+++ b/includes/unl_bootstrap.inc
@@ -4,11 +4,39 @@
  * Do so special setup for UNL specific features.
  */
 function unl_bootstrap() {
+  unl_bootstrap_short_hostname_redirect();
   unl_bootstrap_multisite_without_symlinks();
   unl_bootstrap_proxy_pass_support();
   unl_bootstrap_mobile_internal_redirect();
 }
 
+/**
+ * Check that the hostname resolves to an IP Address.
+ * If it doesn't redirect to <hostname>.unl.edu.
+ */
+function unl_bootstrap_short_hostname_redirect() {
+  $hostname = $_SERVER['HTTP_HOST'];
+  if (gethostbynamel($hostname)) {
+    // The provided host name is just fine.
+    return;
+  }
+  
+  // Otherwise, try adding .unl.edu.
+  $hostname .= '.unl.edu';
+  if (gethostbynamel($hostname)) {
+    // If its a valid domain, redirect to it.
+    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
+      $uri = 'https://';
+    } else {
+      $uri = 'http://';
+    }
+    $uri .= $hostname . $_SERVER['REQUEST_URI'];
+    
+    header('Location: ' . $uri);
+    exit;
+  }
+}
+
 /**
  * Enable the set up of multiple sites without making symbolics links.
  * Instead, a few entries in .htaccess and sites.php will be all that is needed.
-- 
GitLab