I was using IIS rewrite rules in web.config to do my HTTPS and non-www canonical URI enforcement, but then using Web Deploy became complicated so I switched to ASP.NET Core 6 middleware. Here's my code from Program.cs:
app.UseRewriter(new RewriteOptions().AddRedirectToNonWwwPermanent());
app.UseHttpsRedirection();
For http://example.com and https://www.example.com it works great and there is a single redirect.
But, for http://www.example.com it now implements the non-www rule, then the https rule, so you get two 308 redirects chained together (with IIS I had this with a single redirect).
You can test it here: https://www.redirect-checker.org/index.php
Enter: http://www.magazedia.com/
http://www.magazedia.com
308 Permanent Redirect
http://magazedia.com/
308 Permanent Redirect
https://magazedia.com/
200 OK
This plays havoc with my OCD.
Is there a simple fix or do I need to write a custom redirect that combines both?
EDIT:
I also just tried this, but the result is the same (double redirect):
app.UseRewriter(new RewriteOptions().AddRedirectToNonWwwPermanent().AddRedirectToHttpsPermanent() );
// app.UseHttpsRedirection();