Automatically Redirect HTTP requests to HTTPS on IIS 6 |
Jan
17
|
« Windows Server 2008 Standard Installation | Windows 7 Beta Installation » |
Series: Redirecting HTTP to HTTPS
- Automatically Redirect HTTP requests to HTTPS on IIS 7
- Automatically Redirect HTTP requests to HTTPS on IIS 6
- Automatically Redirect HTTP requests to HTTPS using ASP
- Automatically Redirect HTTP requests to HTTPS on IIS 7 using URL Rewrite 2.0
This article is for IIS 6 for the IIS 7 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.
Step 1 – Verify SSL is required for the selected site
1)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Open IIS Manager (Start Menu\Programs\Administrative Tools or %SystemRoot%\system32\inetsrv\iis.msc)
2)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Expand the Computer Name
3)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Expand Web Sites
4)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Right click the web site we wish to modify
5)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Select “Properties”
6)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Select the “Directory Security” tab
7)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Select “Edit” in the Secure Communications section
8)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Check off the “Require secure channel (SSL)” option. (This will only allow pages on this site to be viewed only with https.)
9)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Press OK and close all Properties windows
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
1)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Expand the Computer Name
2)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Expand Web Sites
3)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Right click the web site you wish to modify
4)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Select “Properties”
5)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Select “Custom Errors” Tab
6)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Select the “403;4” error
7)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Press the “Edit” button
8)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Browse to and Select the HttpRedirect.htm file in C:\Inetpub
9)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Press OK and close all Properties windows
Step 4 Ôò¼├┤Ôö£├ºÔö£Ôöñ Test
1)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Bring up a web browser and try to access the site by https, verify that this is working ok
2)╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡╬ô├Â┬╝Ôö£├¡ Try to access the site via http now. You should see the browser change the http:// to https://
Note
In 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. |