Skip to content

Commit 898642c

Browse files
committed
feat: add URL rewriting to redirect non-www to www
1 parent 07d0af0 commit 898642c

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

Web/Program.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Shared;
66
using Web.Extensions;
77
using Web.Services;
8+
using Microsoft.AspNetCore.Rewrite;
89

910
var builder = WebApplication.CreateBuilder(args);
1011

@@ -96,20 +97,25 @@
9697

9798
var app = builder.Build();
9899

100+
var options = new RewriteOptions()
101+
.AddRedirectToNonWwwPermanent();
102+
//.AddRedirectToHttpsPermanent();
103+
app.UseRewriter(options);
104+
99105
// Configure the HTTP request pipeline.
100106
if (!app.Environment.IsDevelopment())
101107
{
102-
app.UseExceptionHandler("/Error");
103-
app.UseHsts();
104-
105-
// Enable compression and caching only in production
106-
app.UseResponseCompression();
107-
app.UseResponseCaching();
108-
app.UseOutputCache();
108+
app.UseExceptionHandler("/Error");
109+
app.UseHsts();
110+
111+
// Enable compression and caching only in production
112+
app.UseResponseCompression();
113+
app.UseResponseCaching();
114+
app.UseOutputCache();
109115
}
110116
else
111117
{
112-
app.UseDeveloperExceptionPage();
118+
app.UseDeveloperExceptionPage();
113119
}
114120

115121
// Enable compression and caching early in the pipeline

0 commit comments

Comments
 (0)