Skip to content

Commit

Permalink
Fix robots.txt showing relative urls (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdemooij9 committed Mar 7, 2023
1 parent b5bc982 commit 78f1e0e
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ public IEnumerable<string> GetSitemapUrls(HttpRequest request)
{
using var ctx = _umbracoContextFactory.EnsureUmbracoContext();
var domains = ctx.UmbracoContext.Domains.GetAll(false).ToArray();
var baseUri = new Uri(request.GetEncodedUrl());
if (domains.Length == 0)
{
yield return $"{new Uri(request.GetEncodedUrl()).GetLeftPart(UriPartial.Authority).TrimEnd('/')}/sitemap.xml";
yield return $"{baseUri.GetLeftPart(UriPartial.Authority).TrimEnd('/')}/sitemap.xml";
}
else
{
foreach (var domain in domains)
{
yield return $"{domain.Name.TrimEnd('/')}/sitemap.xml";
var url = domain.Name.StartsWith('/') ? new Uri(baseUri, domain.Name).ToString() : domain.Name;
yield return $"{url.TrimEnd('/')}/sitemap.xml";
}
}
}
Expand Down

0 comments on commit 78f1e0e

Please sign in to comment.