Skip to content

Commit 35fdf6a

Browse files
committed
Hide base URL in sitemap.xml
1 parent f6a8d69 commit 35fdf6a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/CoreBundle/EventListener/GetSearchablePagesListener.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,12 @@ private function getBaseUrl(array $pageDetails, string $path = null): UrlBuilder
356356
{
357357
$url = new UrlBuilder();
358358
// Set the domain (see contao/core#6421)
359-
$url->setHost($pageDetails['domain'] ?: Environment::get('host'));
359+
$host = $pageDetails['domain'] ?: Environment::get('httpHost');
360+
if (1 === preg_match('/^([^:]+):([\d]+)$/', $host, $matches)) {
361+
$url->setPort($matches[2]);
362+
$host = $matches[1];
363+
}
364+
$url->setHost($host);
360365
$url->setScheme($pageDetails['rootUseSSL'] ? 'https' : 'http');
361366

362367
// Get the path.
@@ -369,7 +374,8 @@ private function getBaseUrl(array $pageDetails, string $path = null): UrlBuilder
369374
true
370375
);
371376
$this->dispatcher->dispatch($event, ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL);
372-
$url->setPath($event->getUrl());
377+
$tempUrl = new UrlBuilder($event->getUrl());
378+
$url->setPath($tempUrl->getPath());
373379
} else {
374380
$url->setPath($path);
375381
}

0 commit comments

Comments
 (0)