title: ASP.NET Core URL Rewriting
body: <p>I am trying to redirect my website from www to non-www rules as well as http to https (<a href="https://example.com" rel="noreferrer">https://example.com</a>) in the middleware. I used to make those redirection change in the web.config such as:</p>
  
  <pre><code> &lt;rewrite&gt;
    &lt;rules&gt;
      &lt;clear /&gt;
      &lt;rule name="Redirect to https" stopProcessing="true"&gt;
        &lt;match url=".*" /&gt;
        &lt;conditions&gt;
          &lt;add input="{HTTPS}" pattern="off" ignoreCase="true" /&gt;
        &lt;/conditions&gt;
        &lt;action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /&gt;
      &lt;/rule&gt;
      &lt;rule name="Redirects to www.domain.com" patternSyntax="ECMAScript" 
              stopProcessing="true"&gt;
          &lt;match url=".*" /&gt;
          &lt;conditions logicalGrouping="MatchAny"&gt;
              &lt;add input="{HTTP_HOST}" pattern="^example.com$" /&gt;
          &lt;/conditions&gt;
          &lt;action type="Redirect" url="https://www.example.com/{R:0}" /&gt;
      &lt;/rule&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>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: <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting" rel="noreferrer">https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting</a> but it didn't help me to force redirect my www to non-www.</p>