0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
JPPINTO
  • Home
  • Blog
  • Certifications
  • About
  • Contact
  • Shop
  • Gallery
  • Current Setup
Contact

Search

April 8, 2009 / IIS 7.0

Automatically Redirect HTTP requests to HTTPS on IIS 7

Featured image for Automatically Redirect HTTP requests to HTTPS on IIS 7

Please Note: This does NOT work on IIS 7.5 or R2. You will get a LOCK VIOLATION due to changes in security in the newer version. Please use the URL Rewrite 2.0 method instead.

This article is for IIS 7 for IIS 6 configuration please refer to this article.

If you configure IIS to only allow https connections, a user will get a 403.4 error when attempting to access the page via http. To fix this problem we create a custom 403.4 page that redirects http requests to https. We will be changing this configuration in a couple of steps:

Step 1 – Verify SSL is required for the selected site
Step 2 – Create a HttpRedirect.htm file and save it to C:InetPub
Step 3 – Set the 403.4 error page to use this file instead of the regular error file
Step 4 – Test

This is a standard 403.4 error message file provided out of the box with IIS 7.

Step 1 – Verify SSL is required for the site

  • Right click the web site
  • Select “Edit BindingsÔò¼├┤Ôö£├ºÔö¼┬¼”

  • Select “AddÔò¼├┤Ôö£├ºÔö¼┬¼”
  • Select the “Type” as “https”
  • Select “IP Address” as “All Unassigned”. NOTE: You can assign multiple SSL Certificate to a server as long as each SSL certificate is using a DIFFERENT IP ADDRESS because only one IP Address can bind the 443 port at a time with IIS
  • Select the “SSL certificate”, select the SSL certificate that you have imported for this website
  • Press OK to continue

You should see the binding for “https” on the list of bindings now

  • Press “Close” to continue

We can stop the configuration here if we wanted users to access the site via http OR https, I want to force users to use https so we will make the next configuration change

  • Under the “Features View”, double click “SSL Settings”

  • Check “Require SSL” and press “Apply”

Step 2 – Create a HttpRedirect.htm file and save it to C:InetPub

We will be creating an HTM file containing the following code. We will save this file to C:Inetpub.

1)””””” Open Notepad and copy in the following code below
2)””””” Go to File > Save as and save this file as HttpRedirect.htm, and save the file to C:Inetpub directory.

You can download a copy of this file here: HttpRedirect.zip


<!-- beginning of HttpRedirect.htm file -->

<script type="text/javascript">

function redirectToHttps()

{

var httpURL = window.location.hostname+window.location.pathname;

var httpsURL = "https://" + httpURL ;

window.location = httpsURL ;

}

redirectToHttps();

</script>

<!-- end of HttpRedirect.htm file -->

 
 

Step 3 – Set the 403 error page to use this file instead of the regular error file

You can do this at the SERVER or SITE level. If you perform this action at the SERVER level it will be effective for all sites on the server and if you perform this action at the site level it will only be applicable to that website

  • Select the server name on the left side under “Connections”
  • Under the “features view” on the right side, double click “Error Pages”

  • Select “AddÔò¼├┤Ôö£├ºÔö¼┬¼”

  • Set the status code as “403.4”
  • Set the file to “C:InetpubhttpsRedirect.htm”
  • Press “OK”

  • You should now see the 403.4 error listed with the other error codes
  • Select the error code and press “Edit Feature SettingsÔò¼├┤Ôö£├ºÔö¼┬¼”

  • Change to “Custom error pages”
  • Change the path of the page to “C:InetpubhttpsRedirect.htm”
  • Change the path type to “file”
  • Press OK

Step 4 – Testing the website

  • To test go to HTTPS https://www.sitename.com, you should go to the site with no problems.
  • If you go to HTTP http://www.sitename.com you should not get a 403.4 error. It should redirect to HTTPS
NoteIn the unlikely event that a client does not have JavaScript enabled, this will not work. JavaScript must be enabled on the client machine for this to work.

 
 

Post Views: 3,446
<- Moving an SSL certificate from Windows 2003 Server to Windows Server 2008
Error when opening an EXE file ->

Categories

  • Active Directory (5)
  • AI (3)
  • Amazon Cloud Services (1)
  • AWS (2)
  • Blazor (1)
  • C# (C-Sharp) (3)
  • CI/CD Pipelines (1)
  • Cloud (1)
  • Cloudflare (2)
  • Codex (1)
  • Containers (4)
  • Deployment (2)
  • Development (5)
  • DNS (1)
  • Docker (3)
  • Email (1)
  • Family (1)
  • General (5)
  • IIS 6.0 (4)
  • IIS 7.0 (10)
  • IIS 8.0 (1)
  • Infrastructure as Code (IaC) (1)
  • Kubernetes (3)
  • Linux (9)
  • Microsoft 365 (2)
  • MySQL (1)
  • Office 2010 (1)
  • PHP (1)
  • PowerShell (11)
  • Productivity (1)
  • Security (1)
  • Servers (9)
  • SharePoint 2007 (8)
  • SharePoint 2010 (19)
  • SharePoint 2013 (2)
  • SharePoint Online (1)
  • SMTP (4)
  • SQL Server 2008 (1)
  • SQL Server 2008 R2 (1)
  • SQL Server 2012 (2)
  • SQL Server 2019 (1)
  • SSL (1)
  • Travel (1)
  • Troubleshooting (1)
  • Ubuntu (9)
  • Uncategorized (1)
  • URL Rewrite (2)
  • Visual Studio 2019 (1)
  • Visual Studio Code (1)
  • Windows 10 (7)
  • Windows 2003 (9)
  • Windows 2008 (18)
  • Windows 2012 (6)
  • Windows 7 (3)
  • Windows Firewall (1)
  • Windows Vista (1)
  • WordPress (3)
  • WP-CLI (3)

Recent Posts

  • GPT-5.6 Sol Changes How We Prompt—and How We Write AGENTS.md
  • Protect a Domain That Does Not Send Email with SPF, DMARC, and Null MX
  • Turning Our Atlanta Vacation Photos into a Video with PowerShell
  • Bulk Create Cloudflare Origin CA Certificates with PowerShell
  • Test a Cloudflare Global API Key Connection with PowerShell

Advertisement

Tags

agents.md ai coding agents aws bash cloudflare cloud storage codex context engineering developer workflow dev to production dns externalize blob externalize sharepoint data full installation http redirect https IIS IIS installation index server configuration installing cumulative updates linux load balance central administration microsoft 365 nginx powerpoint powershell redirect http to https s3 server setup sharepoint 2010 cumulative updates sharepoint 2010 farm build sharepoint 2010 farm configuration sharepoint 2010 farm installation sharepoint data externalization SMTP ssl storagepoint ubuntu web server windows Windows 7 windows server 2008 wordpress wp-cli x86
© 2026 JPPinto.com. All rights reserved.