Skip to content

Commit 067ca27

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 bf8390a commit 067ca27

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
@@ -515,6 +515,20 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
515515
app.UseSecurityHeadersMiddleware(new SecurityHeadersBuilder()
516516
.AddDefaultSecurePolicy()
517517
.AddContentSecurityPolicy(csp));
518+
519+
// Redirect www.essentialcsharp.com → essentialcsharp.com (permanent 301)
520+
// Must be after UseForwardedHeaders so the Host header reflects the real hostname.
521+
app.Use(async (context, next) =>
522+
{
523+
if (context.Request.Host.Host.StartsWith("www.", StringComparison.OrdinalIgnoreCase))
524+
{
525+
string apexHost = context.Request.Host.Host[4..];
526+
string redirectUrl = $"{context.Request.Scheme}://{apexHost}{context.Request.PathBase}{context.Request.Path}{context.Request.QueryString}";
527+
context.Response.Redirect(redirectUrl, permanent: true);
528+
return;
529+
}
530+
await next(context);
531+
});
518532
}
519533
else
520534
{

0 commit comments

Comments
 (0)