How to redirect http to https in IIS7.5

How to redirect http to https in IIS7.5

If you ever want to force your http traffic to https on IIS7 you can do the steps below. The steps here have been obtained after going through various forums and links which we tested and tried out. This worked for us so we're putting it up here for everyone.

How to redirect HTTP traffic to HTTPS on IIS7.

1. In IIS, click on the site name, and go to the SSL Settings section.

2. Check Require SSL and Require 128-bit SSL and click Apply.




4. Create a new text file and paste the following into it:

<html>
<head><title>Redirecting...</title></head>
<script language="JavaScript">
function redirectHttpToHttps()
{
    var httpURL= window.location.hostname + window.location.pathname + window.location.search;
    var httpsURL= "https://" + httpURL;
    window.location = httpsURL;
}
redirectHttpToHttps();
</script>
<body>
</body>
</html>


5. Save the file as redirectToHttps.htm in your C:\Inetpub directory.

6.Back in IIS, click on the site name and double-click the Error Pages option.

7. Click Add… and enter 403.4 as the Status code. Browse for the redirectToHttps.htm file you just created and click OK.

8. Select the error code and press Edit Feature Settings…

9. Click the Custom error pages option and again browse for the redirectToHttps.htm file.

Here if you get an error in IIS saying "Lock violation" then you need to do the steps below.

a. Open the file %windir%\System32\inetsrv\config\applicationHost.config in Notepad. Run Notepad as the administrator if you're having problems.

You'll see something like this:

<httpErrors lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">

Remove the ,defaultPath section and save.

b. Also in the web.config file which is now created in your website root you will have to change the path from absolute to virtual
e.g.
Change below from
<error statusCode="403" subStatusCode="4" path="c:\inetpub\HttpRedirect.htm" responseMode="File" />

To

<error statusCode="403" subStatusCode="4" path="HttpRedirect.htm" responseMode="File" />

Now save the web.config.

10. Test the site by going to http://www.yoursite.com and making sure it redirects


Pratik Monday 17 June 2013 - 10:58 pm | | Default
Used tags: , , , ,

two comments

srinadh

Im getting you do not have permission to view this directory or page. so please let me know, how can i over come this problem,

srinadh, - 21-12-’14 11:36

One or more comments are waiting for approval by an editor.

(optional field)
(optional field)

Comment moderation is enabled on this site. This means that your comment will not be visible until it has been approved by an editor.

Remember personal info?
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.