summaryrefslogtreecommitdiff
path: root/app/Helpers
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-11-16 19:18:02 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-11-16 19:18:02 +0000
commit22de662b19d3bab2621cf42ee26969092c73d4c1 (patch)
treefe27d7a3e5ed5f3984b56d688c9ff24125f21d41 /app/Helpers
parentdc6156d0b8e2208e9bec8da8967fa5ce33109652 (diff)
downloadwebtrees-22de662b19d3bab2621cf42ee26969092c73d4c1.tar.gz
webtrees-22de662b19d3bab2621cf42ee26969092c73d4c1.tar.bz2
webtrees-22de662b19d3bab2621cf42ee26969092c73d4c1.zip
Fix: make pretty URLs absolute
Diffstat (limited to 'app/Helpers')
-rw-r--r--app/Helpers/functions.php10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/Helpers/functions.php b/app/Helpers/functions.php
index 0338c820ff..2f50ad847d 100644
--- a/app/Helpers/functions.php
+++ b/app/Helpers/functions.php
@@ -164,6 +164,7 @@ function response($content = '', $code = StatusCodeInterface::STATUS_OK, $header
function route(string $route_name, array $parameters = []): string
{
$request = app(ServerRequestInterface::class);
+ $base_url = $request->getAttribute('base_url');
$router_container = app(RouterContainer::class);
$route = $router_container->getMap()->getRoute($route_name);
@@ -175,9 +176,12 @@ function route(string $route_name, array $parameters = []): string
return strpos($route->path, '{' . $key . '}') === false && strpos($route->path, '{/' . $key . '}') === false;
}, ARRAY_FILTER_USE_KEY);
- // Turn the pretty URL into an ugly one.
- if ($request->getAttribute('rewrite_urls') !== '1') {
- $base_url = $request->getAttribute('base_url');
+ if ($request->getAttribute('rewrite_urls') === '1') {
+ // Make the pretty URL absolute.
+ $base_path = parse_url($base_url, PHP_URL_PATH) ?? '';
+ $url = substr($base_url, 0, -strlen($base_path)) . $url;
+ } else {
+ // Turn the pretty URL into an ugly one.
$path = parse_url($url, PHP_URL_PATH);
$parameters = ['route' => $path] + $parameters;
$url = $base_url . '/index.php';