. Redirect HTTP To HTTPS With g | My Tec Bits
Redirect HTTP To HTTPS With g | My Tec Bits
Redirect HTTP To HTTPS With g | My Tec Bits

Redirect HTTP To HTTPS With web.config

Recently I’ve installed SSL certificate to my ASP.NET website. As my website was already indexed in search engines and referred by several other websites without SSL and just using the HTTP protocol. So, when changing the protocol to HTTPS, I’ve to make sure all the requests urls with http should be redirected to its equivalent HTTPS urls. It is easy to redirect HTTP to HTTPS protocol using the IIS URL Redirect Module and few lines of code in web.config. Follow these steps to redirect http to https with web.config.

Forcing HTTP to HTTPS using web.config

  1. The first thing you have to do is install URL Rewrite Module for the IIS. You can install the latest version of URL Redirect Module from https://www.iis.net/downloads/microsoft/url-rewrite. If you think the redirect module is already installed on the server, then you can confirm it by verifying the registry key \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\URL Rewrite.
  2. Once the URL Rewrite Module is installed, add the below lines of code in your web application’s web.config file inside .
” pattern=”off” ignoreCase=”true” /> ” redirectType=”Permanent” appendQueryString=”false” />

This rewrite rule in web.config does a permanent redirection to the equivalent https url. For example, the non secured url http://www.somedomain.com/somepage.aspx will be redirected to https://www.somedomain.com/somepage.aspx with a 301 HTTPS status code stating a permanent redirection. This method helps to retain the search engine indexing and ranking of the website from before implementing the SSL protocol.

Related Articles

  • Solution for HTTP Error 404.13 – Not Found; deny a request that exceeds the request content length.

Reference

  • About Using IIS URL Rewrite Module.
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print
You may also like. Categories IIS, Web Security Tags ASP.NET, IIS 7, IIS 7.5, IIS 8, IIS 8.5, IIS10, Web Site 2 thoughts on “Redirect HTTP To HTTPS With web.config”

When I configure my web.config like that I get ERR_TOO_MANY_REDIRECTS. I am working on that problem since hours. Do you have any idea? Reply

Hi Dominik Lienen, Please go through the web.config and check if there is any other rule redirecting to a http url. Reply

Leave your thoughts. Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Article Categories

  • Android (2)
  • Apple (22)
    • macOS (22)
    • DNN (4)
    • Java Script (10)
    • Jquery (8)
    • PHP (7)
    • Python (83)
    • Twitter Bootstrap (25)
    • Web Security (11)
    • Zurb Foundation (6)
    • .Net (69)
    • IIS (10)
    • Internet Explorer (3)
    • Office (2)
    • SQL Server (225)
    • Windows (24)
    • Java (2)
    • Oracle Database (5)

    Recent Articles

    • Installing .NET SDK in Linux Mint and debugging C# code using VS Code Jun 21, 2024
    • Generating random number in C# Jun 6, 2024
    • How to calculate running total in SQL Server? Apr 27, 2024
    • How to import XML data into SQL Server using SELECT query? Apr 10, 2024
    • How to prevent VS Code from replacing an already opened preview tab with a subsequently opened one? Mar 13, 2024
    • Separating letters and numbers from strings in SQL Server Mar 6, 2024
    • How to call or run another application from python code? Feb 15, 2024
    • How to store images in SQL Server? Jan 17, 2024
    • Error: A table that has FILESTREAM columns must have a nonnull unique column with the ROWGUIDCOL property. Jan 8, 2024
    • Fix for Error: “FILESTREAM feature is disabled” while adding FILESTREAM Jan 4, 2024

    Subscribe MyTecBits.com

    Online Tools

    • Fitness Calculators
    • Encoders & Decoders
    • Cryptography
    • Unit Converters
    • Math. Calculators
    • Date & Time Calculators
    • Finance Calculators

    Popular Articles

    • Clean way to uninstall Docker on macOS
    • How to exit from single-user mode in SQL Server database?
    • Where is SQL Server Configuration Manager?
    • Reading XML file with PHP
    • How to connect SQL Server from Python on macOS?

    Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use. Learn more.