KnowledgebaseHow can we help you?

Redirect HTTP to HTTPS automatically in .Net

Using the following code in your web.config file automatically redirects visitors to the HTTPS version of your site:

<configuration>
<system.webServer>
<rewrite>
    <rules>
	<rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
	<match url="(.*)" /> 
	<conditions> 
		<add input="{HTTPS}" pattern="off" ignoreCase="true" />
	</conditions> 
	<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>   
    </rules>
</rewrite>
</system.webServer>
</configuration>

If you have an existing web.config file:

  • Ensure you have sections (i.e. opening and closing tags) for:
    • system.webServer (which contains rewrite)
    • rewrite (which contains rules)
    • rules (which contains one or more rule sections)
    Insert any of those sections that do not exist.
  • Insert the entire rule section, including match, conditions, and action, inside the rules section.

Was this answer helpful?

Also Read

Gen X Web Hosting
Have a question? Call us.
+91 94296 92542
10:00 am – 7:30 pm IST, Mon–Sat
Live chat, email & tickets 24/7
Hosting
Linux Shared Windows Shared Reseller Hosting Node X Virtual Cloud Dedicated Servers
Products
Register Domains Transfer Domains SSL Certificates n8n Hosting Business Email
Company
About Us Contact Us Blog Careers Affiliates
Support
Open Ticket Knowledgebase Support Center
HostAdvice Great Uptime Award for Gen X Web Hosting Gen X Web Hosting Reviews Gen X Web Hosting Reviews
Copyright © 2026 Gen X Web Hosting. All rights reserved.
Privacy Policy Terms of Use Site Map