diff --git a/src/UrlInfo/UrlInfo.php b/src/UrlInfo/UrlInfo.php index 812b636..0ee8f84 100644 --- a/src/UrlInfo/UrlInfo.php +++ b/src/UrlInfo/UrlInfo.php @@ -123,7 +123,7 @@ class UrlInfo { $url .= ':' . $this->getPort(); } if ($this->hasPath()) { - $url .= ($url === '' || !$this->isPathAbsolute() ? '' : '/') . $this->getPath(); + $url .= ($this->hasHost() && !$this->isPathAbsolute() ? '/' : '') . $this->getPath(); } if ($this->hasArguments()) { $url .= '?' . $this->getArgumentsAsString(); @@ -304,7 +304,7 @@ class UrlInfo { * @return string|null The URL path */ public function getPath (): ?string { - return $this->hasPathParts() ? $this->getPathParts()->join('/') : null; + return $this->hasPathParts() ? preg_replace('#/{2,}#', '/', $this->getPathParts()->join('/')) : null; } /** * The URL path parts