]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
redirect on non-canonical server name
authorEvan Prodromou <evan@controlyourself.ca>
Mon, 15 Jun 2009 23:40:53 +0000 (16:40 -0700)
committerEvan Prodromou <evan@controlyourself.ca>
Mon, 15 Jun 2009 23:40:53 +0000 (16:40 -0700)
classes/Status_network.php

index bf05ad61e00150c9e79d32592fd3473e1672f2cc..eef27d76533db85360c8036e6f586ce8a52cc23c 100644 (file)
@@ -61,6 +61,9 @@ class Status_network extends DB_DataObject
         }
 
         if (!empty($sn)) {
+            if (!empty($sn->hostname) && 0 != strcasecmp($sn->hostname, $servername)) {
+                $sn->redirectToHostname();
+            }
             $dbhost = (empty($sn->dbhost)) ? 'localhost' : $sn->dbhost;
             $dbuser = (empty($sn->dbuser)) ? $sn->nickname : $sn->dbuser;
             $dbpass = $sn->dbpass;
@@ -82,4 +85,29 @@ class Status_network extends DB_DataObject
             return null;
         }
     }
+
+    // Code partially mooked from http://www.richler.de/en/php-redirect/
+    // (C) 2006 by Heiko Richler  http://www.richler.de/
+    // LGPL
+
+    function redirectToHostname()
+    {
+        $destination = 'http://'.$this->hostname;
+        $destination .= $_SERVER['REQUEST_URI'].
+          $_SERVER['QUERY_STRING'];
+
+        $old = 'http'.
+          (($_SERVER['HTTPS'] == 'on') ? 'S' : '').
+          '://'.
+          $_SERVER['HTTP_HOST'].
+          $_SERVER['REQUEST_URI'].
+          $_SERVER['QUERY_STRING'];
+        if ($old == $destination) { // this would be a loop!
+            // error_log(...) ?
+            return false;
+        }
+
+        common_redirect($destination, 301);
+        // shouldn't get here
+    }
 }