add support for root sitemap.xml and robots.txt
This commit is contained in:
parent
9e0a4dfac8
commit
e34b1b54d5
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Shared;
|
using Oqtane.Shared;
|
||||||
|
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
@ -60,6 +61,22 @@ namespace Oqtane.Infrastructure
|
|||||||
context.Request.Path = path.Replace("/" + alias.Path, "");
|
context.Request.Path = path.Replace("/" + alias.Path, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle sitemap.xml root request (does not support subfolder aliases)
|
||||||
|
if (context.Request.Path.StartsWithSegments("/sitemap.xml"))
|
||||||
|
{
|
||||||
|
context.Request.Path = "/pages" + context.Request.Path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle robots.txt root request (does not support subfolder aliases)
|
||||||
|
if (context.Request.Path.StartsWithSegments("/robots.txt"))
|
||||||
|
{
|
||||||
|
// allow all and specify site map
|
||||||
|
var robots = $"User-agent: *\n\nSitemap: {context.Request.Scheme}://{alias.Name}/pages/sitemap.xml";
|
||||||
|
context.Response.ContentType = "text/plain";
|
||||||
|
await context.Response.WriteAsync(robots);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user