Skip to content

Commit

Permalink
deal with in-docroot installs and custom rewrites properly
Browse files Browse the repository at this point in the history
  • Loading branch information
WanWizard committed Jul 14, 2013
1 parent e8c7ac2 commit a1ac30d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions base.php
Expand Up @@ -363,3 +363,27 @@ function http_build_url($url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new
;
}
}

if ( ! function_exists('get_common_path'))
{
function get_common_path($paths)
{
$lastOffset = 1;
$common = '/';
while (($index = strpos($paths[0], '/', $lastOffset)) !== false)
{
$dirLen = $index - $lastOffset + 1; // include /
$dir = substr($paths[0], $lastOffset, $dirLen);
foreach ($paths as $path)
{
if (substr($path, $lastOffset, $dirLen) != $dir)
{
return $common;
}
}
$common .= $dir;
$lastOffset = $index + 1;
}
return $common;
}
}
3 changes: 2 additions & 1 deletion classes/fuel.php
Expand Up @@ -264,7 +264,8 @@ protected static function generate_base_url()
}
if (\Input::server('script_name'))
{
$base_url .= str_replace('\\', '/', dirname(\Input::server('script_name')));
$common = get_common_path(array(\Input::server('request_uri'), \Input::server('script_name')));
$base_url .= $common;
}

// Add a slash if it is missing and return it
Expand Down
2 changes: 1 addition & 1 deletion classes/input.php
Expand Up @@ -134,7 +134,7 @@ public static function uri()
// Fall back to parsing the REQUEST URI
if (isset($_SERVER['REQUEST_URI']))
{
$uri = $_SERVER['REQUEST_URI'];
$uri = strpos($_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI']) !== 0 ? $_SERVER['REQUEST_URI'] : '';
}
else
{
Expand Down

0 comments on commit a1ac30d

Please sign in to comment.