Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problem that redirect does not work when placed in subdirectory. #1132

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,6 @@ public function getFile(string $fileID)
*/
protected function detectURI($protocol, $baseURL)
{
$this->uri->setPath($this->detectPath($protocol));

// It's possible the user forgot a trailing slash on their
// baseURL, so let's help them out.
$baseURL = ! empty($baseURL) ? rtrim($baseURL, '/ ') . '/' : $baseURL;
Expand All @@ -585,7 +583,7 @@ protected function detectURI($protocol, $baseURL)
$this->uri->setScheme(parse_url($baseURL, PHP_URL_SCHEME));
$this->uri->setHost(parse_url($baseURL, PHP_URL_HOST));
$this->uri->setPort(parse_url($baseURL, PHP_URL_PORT));
$this->uri->resolveRelativeURI(parse_url($baseURL, PHP_URL_PATH));
$this->uri->setBasePath(parse_url($baseURL, PHP_URL_PATH));
} else
{
// @codeCoverageIgnoreStart
Expand All @@ -595,6 +593,9 @@ protected function detectURI($protocol, $baseURL)
}
// @codeCoverageIgnoreEnd
}

$path = $this->detectPath($protocol);
$this->uri->setPath($this->uri->trimBasePath($path));
}

//--------------------------------------------------------------------
Expand Down
39 changes: 37 additions & 2 deletions system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class URI
*/
protected $path;

/**
* URI base path.
*
* @var string
*/
protected $basePath;

/**
* The name of any fragment.
*
Expand Down Expand Up @@ -383,7 +390,7 @@ public function getPort()
*/
public function getPath(): string
{
return (is_null($this->path)) ? '' : $this->path;
return (is_null($this->path)) ? '' : $this->basePath.$this->path;
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -969,6 +976,34 @@ protected function applyParts($parts)
}
}

/**
* Set path that will not be changed.
*
* @param string $path
*/
public function setBasePath(string $path) : void
{
$this->basePath = rtrim($path, '/');
}

/**
* trim basePath
*
* @param string $path
*
* @return string
*/
public function trimBasePath(string $path) : string
{
$path = '/'.ltrim($path, '/');
$base_path = $this->basePath ?? '';
if (strlen($base_path) && strpos($path, $base_path) === 0) {
return substr($path, strlen($base_path));
}

return $path;
}

//--------------------------------------------------------------------

/**
Expand Down Expand Up @@ -1023,7 +1058,7 @@ public function resolveRelativeURI(string $uri)
{
if (strpos($relative->getPath(), '/') === 0)
{
$transformed->setPath($relative->getPath());
$transformed->setPath($this->basePath . $relative->getPath());
}
else
{
Expand Down