I have created a redirect rules in my web.config to redirect my website from http to https. The issue i have is that every single link on the website is now https. I have a lots of link to other website which don't have SSL and therefore i get certificate errors. This is what i have done:
  <rewrite>
  <rules>
    <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny">
        <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>
How can i redirect https only for my domain and not every links on my website?
Require HTTPS. We recommend that production ASP.NET Core web apps use: HTTPS Redirection Middleware (UseHttpsRedirection) to redirect HTTP requests to HTTPS. HSTS Middleware (UseHsts) to send HTTP Strict Transport Security Protocol (HSTS) headers to clients.
Edit: While it still works, things changed a bit since I wrote this answer. Please check D.L.MAN's more up to date answer: https://stackoverflow.com/a/56800707/844207
In asp.net Core 2 you can use an URL Rewrite independent of the Web Server, by using app.UseRewriter in Startup.Configure, like this:
        if (env.IsDevelopment())
        {
            app.UseBrowserLink();
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // todo: replace with app.UseHsts(); once the feature will be stable
            app.UseRewriter(new RewriteOptions().AddRedirectToHttps(StatusCodes.Status301MovedPermanently, 443));
        }
                        Actually (ASP.NET Core 1.1) there is a middleware named Rewrite that includes a rule for what you are trying to do.
You can use it on Startup.cs like this:
var options = new RewriteOptions()
    .AddRedirectToHttpsPermanent();
app.UseRewriter(options);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With