diff --git a/src/Routing/Route.php b/src/Routing/Route.php index 0e054e6..4937930 100644 --- a/src/Routing/Route.php +++ b/src/Routing/Route.php @@ -167,7 +167,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array ? [$host] : array_reverse(explode('.', $host)); $re = strtr($re, [ - '/%basePath%/' => preg_quote($url->getBasePath(), '#'), + '/%basePath%/' => preg_quote($url->getBasePath() . '/', '#'), '%tld%' => preg_quote($parts[0], '#'), '%domain%' => preg_quote(isset($parts[1]) ? "$parts[1].$parts[0]" : $parts[0], '#'), '%sld%' => preg_quote($parts[1] ?? '', '#'), @@ -176,11 +176,11 @@ public function match(Nette\Http\IRequest $httpRequest): ?array } elseif ($this->type === self::Relative) { $basePath = $url->getBasePath(); - if (strncmp($url->getPath(), $basePath, strlen($basePath)) !== 0) { + if (strncmp($url->getPath(), $basePath.'/', strlen($basePath.'/')) !== 0) { return null; } - $path = substr($url->getPath(), strlen($basePath)); + $path = substr($url->getPath(), strlen($basePath.'/')); } else { $path = $url->getPath(); @@ -262,7 +262,7 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri // absolutize if ($this->type === self::Relative) { - $url = (($tmp = $refUrl->getAuthority()) ? "//$tmp" : '') . $refUrl->getBasePath() . $url; + $url = (($tmp = $refUrl->getAuthority()) ? "//$tmp" : '') . $refUrl->getBasePath() . '/' . $url; } elseif ($this->type === self::Path) { $url = (($tmp = $refUrl->getAuthority()) ? "//$tmp" : '') . $url; @@ -274,7 +274,7 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri : array_reverse(explode('.', $host)); $port = $refUrl->getDefaultPort() === ($tmp = $refUrl->getPort()) ? '' : ':' . $tmp; $url = strtr($url, [ - '/%basePath%/' => $refUrl->getBasePath(), + '/%basePath%/' => $refUrl->getBasePath() . '/', '%tld%' => $parts[0] . $port, '%domain%' => (isset($parts[1]) ? "$parts[1].$parts[0]" : $parts[0]) . $port, '%sld%' => $parts[1] ?? '', diff --git a/src/Routing/RouteList.php b/src/Routing/RouteList.php index 3c4bc42..179fd8a 100644 --- a/src/Routing/RouteList.php +++ b/src/Routing/RouteList.php @@ -67,7 +67,7 @@ protected function prepareRequest(Nette\Http\IRequest $httpRequest): ?Nette\Http $url = $httpRequest->getUrl(); $relativePath = $url->getRelativePath(); if (strncmp($relativePath, $this->path, strlen($this->path)) === 0) { - $url = $url->withPath($url->getPath(), $url->getBasePath() . $this->path); + $url = $url->withPath($url->getPath(), $url->getBasePath() . '/' . $this->path); } elseif ($relativePath . '/' === $this->path) { $url = $url->withPath($url->getPath() . '/'); } else { @@ -104,7 +104,7 @@ public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?stri if ($this->path) { if (!isset($this->refUrlCache[$refUrl])) { - $this->refUrlCache[$refUrl] = $refUrl->withPath($refUrl->getBasePath() . $this->path); + $this->refUrlCache[$refUrl] = $refUrl->withPath($refUrl->getBasePath() . '/' . $this->path); } $refUrl = $this->refUrlCache[$refUrl];