summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-06-15 16:40:53 -0700
committerEvan Prodromou <evan@controlyourself.ca>2009-06-15 16:40:53 -0700
commit587b7a8b2ad0b260cc3159da260a4d439c2a5f0c (patch)
treeadf8b95910d7df582961c878c50d93ba56fb9a59 /classes
parentfbed704f3b6a8237e815be9586eb753cc78d20c3 (diff)
redirect on non-canonical server name
Diffstat (limited to 'classes')
-rw-r--r--classes/Status_network.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/classes/Status_network.php b/classes/Status_network.php
index bf05ad61e..eef27d765 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
+ }
}