obscuresausage
07/24/2023, 4:10 PMMike Chambers
07/24/2023, 5:10 PMpublic void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var rewriteOptions = new RewriteOptions()
.AddRedirect("^news-story/(.*)$", "/news/$1", StatusCodes.Status301MovedPermanently)
...
}
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0#irule-based-ruleMike Chambers
07/24/2023, 5:14 PMMike Chambers
07/24/2023, 5:18 PM[umbracoRedirectUrl]
tableMike Chambers
07/24/2023, 5:20 PMMike Chambers
07/24/2023, 5:21 PMobscuresausage
07/24/2023, 5:21 PMMike Chambers
07/24/2023, 5:22 PMMike Chambers
07/24/2023, 5:26 PMobscuresausage
07/24/2023, 8:18 PMDan 'Diplo' Booth
07/25/2023, 6:41 PMstartup.cs
file:
app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "IISUrlRewrite.xml"));
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0Mike Chambers
07/26/2023, 9:06 AM<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule">
<match url=".*" />
<conditions>
<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="{C:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="StaticRewrites">
<add key="{OLD}" value="{NEW}" />
</rewriteMap>
</rewrite>
</system.webServer>
and IIS will handle the redirects natively before the aspnet process gets involved, with improved performance.. Inded the MS docs actually advise you only to use UseRewriter if you can't use IIS native.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-7.0#when-to-use-url-rewriting-middleware
Use URL Rewriting Middleware when the following approaches aren't satisfactory:
- URL Rewrite module with IIS on Windows Server
- Apache mod_rewrite module on Apache Server
- URL rewriting on Nginx