From 587b7a8b2ad0b260cc3159da260a4d439c2a5f0c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:40:53 -0700 Subject: [PATCH] redirect on non-canonical server name --- classes/Status_network.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/classes/Status_network.php b/classes/Status_network.php index bf05ad61e0..eef27d7653 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -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 + } } -- 2.39.5