Skip to content

Commit

Permalink
#15 Workaround for apache style userdir (~username) routing
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Aug 18, 2014
1 parent 620c204 commit 1295637
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ class Uri
*/
public function __construct()
{

$base = 'http://';
$uri = $_SERVER["REQUEST_URI"];
$uri = $_SERVER['REQUEST_URI'];
$root_path = rtrim(substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], 'index.php')), '/');


if (isset($_SERVER["HTTPS"])) {
$base = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if (isset($_SERVER['HTTPS'])) {
$base = (@$_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
}

$base .= $_SERVER["SERVER_NAME"];
$base .= $_SERVER['SERVER_NAME'];

if ($_SERVER['SERVER_PORT'] != '80' && $_SERVER['SERVER_PORT'] != '443') {
$base .= ":".$_SERVER['SERVER_PORT'];
}

if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
$base .= ":".$_SERVER["SERVER_PORT"];
// check if userdir in the path and workaround PHP bug with PHP_SELF
if (strpos($_SERVER['REQUEST_URI'], '/~') !== false && strpos($_SERVER['PHP_SELF'], '/~') === false) {
$root_path = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '/', 1)) . $root_path;
}

$this->base = $base;
$this->root = $base . rtrim(substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], 'index.php')), '/');
$this->root = $base . $root_path;
$this->url = $base . $uri;

$this->init();
Expand Down

0 comments on commit 1295637

Please sign in to comment.