Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge
  • All
  • C#
  • MVC
  • Web API
  • Azure
  • IIS
  • JavaScript
  • Angular
  • Node.js
  • Java
  • Python
  • SQL Server
  • SEO
  • Entrepreneur
  • Productivity

Redirect from HTTP to HTTPS

You can redirect from HTTP to HTTP request in ASP.NET website using the web.config in ASP.NET web sites.

Open web.config file in the root directory of your website and add the following <rewrite> section in the <system.webServer> section.

Example: Redirect from HTTP to HTTPS in web.config
<rewrite>
    <rules>
        <rule name="HttpToHttps" stopProcessing="true">
            <match url=".*" ignoreCase="true" />
            <conditions>
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
                <action type="Redirect" redirectType="Permanent" url="https://www.mywebsite.com/{`{R:0}`}" />
        </rule>
    </rules>
</rewrite>

You can remove redirection if you are running it in your development machine localhost by adding one more condition, as shown below.

Example: Ignore localhost
<rewrite>
    <rules>
        <rule name="HttpToHttps" stopProcessing="true">
            <match url=".*" ignoreCase="true" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="localhost" negate="true"/>
                <add input="{HTTPS}" pattern="^OFF$"/>
            </conditions>
                <action type="Redirect" redirectType="Permanent" url="https://www.mywebsite.com/{`{R:0}`}" />
        </rule>
    </rules>
&lt;rewrite&gt;

Redirect to HTTPS in ClouldFlare

You can redirect from HTTP to HTTP from Cloudflare. Go to SSL/TLS -> Edge Certificates and turn on the Always Use HTTPS.

Redirect to HTTPS in CloudFlare

Redirect to HTTPS in Azure

If your website is hosted on azure then you can redirect from HTTP to HTTP requests by configuring your app service.

Select your app service and go to configuration -> General settings tab and select HTTPS Only flag to On.

Redirect to HTTPS in Azure
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.