Skip to content

Commit 5f422e0

Browse files
feat: redirect www.essentialcsharp.com to apex domain
Adds a 301 redirect in the production middleware pipeline that strips the 'www.' prefix and redirects to the apex domain. Runs after UseForwardedHeaders so the real Host header is available behind the Azure Container Apps ingress proxy.
1 parent d349822 commit 5f422e0

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

EssentialCSharp.Web/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,20 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
493493
app.UseSecurityHeadersMiddleware(new SecurityHeadersBuilder()
494494
.AddDefaultSecurePolicy()
495495
.AddContentSecurityPolicy(csp));
496+
497+
// Redirect www.essentialcsharp.com → essentialcsharp.com (permanent 301)
498+
// Must be after UseForwardedHeaders so the Host header reflects the real hostname.
499+
app.Use(async (context, next) =>
500+
{
501+
if (context.Request.Host.Host.StartsWith("www.", StringComparison.OrdinalIgnoreCase))
502+
{
503+
string apexHost = context.Request.Host.Host[4..];
504+
string redirectUrl = $"{context.Request.Scheme}://{apexHost}{context.Request.PathBase}{context.Request.Path}{context.Request.QueryString}";
505+
context.Response.Redirect(redirectUrl, permanent: true);
506+
return;
507+
}
508+
await next(context);
509+
});
496510
}
497511
else
498512
{

0 commit comments

Comments
 (0)