I am trying to redirect my website from www to non-www rules as well as http to https (https://example.com) in the middleware. I used to make those redirection change in the web.config such as:
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirects to www.domain.com" patternSyntax="ECMAScript"
stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
I am new to asp.net core and would like to know how can i make those redirection in my middleware? I read this article: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting but it didn't help me to force redirect my www to non-www.