Skip to content

Commit c50edf9

Browse files
bandrzejkonklone
authored andcommitted
IIS 7.0+ example HSTS fix (#238)
* HSTS fix for IIS * Fixed IIS statement
1 parent 89d42d1 commit c50edf9

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

pages/hsts.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,38 @@ On **Apache**, you would apply a `Header` directive to always set the HSTS heade
127127
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
128128
```
129129

130-
On **Microsoft systems running IIS** (Internet Information Services), there are no ".htaccess" files to implement custom headers. IIS applications use a central "web.config" file for configuration. For IIS 7.0 and up, the code is as follows:
131-
132-
```
133-
<httpProtocol>
134-
<customHeaders>
135-
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; preload "/>
136-
</customHeaders>
137-
</httpProtocol>
130+
On **Microsoft systems running IIS** (Internet Information Services), there are no ".htaccess" files to implement custom headers. IIS applications use a central `web.config` file for configuration.
131+
132+
For IIS 7.0 and up, the example `web.config` file configuration below will handle secure HTTP to HTTPS redirection with HSTS enabled for HTTPS:
133+
134+
```
135+
<?xml version="1.0" encoding="UTF-8"?>
136+
<configuration>
137+
<system.webServer>
138+
<rewrite>
139+
<rules>
140+
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
141+
<match url="(.*)" />
142+
<conditions>
143+
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
144+
</conditions>
145+
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
146+
redirectType="Permanent" />
147+
</rule>
148+
</rules>
149+
<outboundRules>
150+
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
151+
<match serverVariable="RESPONSE_Strict_Transport_Security"
152+
pattern=".*" />
153+
<conditions>
154+
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
155+
</conditions>
156+
<action type="Rewrite" value="max-age=31536000; includeSubDomains; preload" />
157+
</rule>
158+
</outboundRules>
159+
</rewrite>
160+
</system.webServer>
161+
</configuration>
138162
```
139163

140164
Generally, you want to set a custom HTTP header for `Strict-Transport-Security` with the value `max-age=31536000; includeSubDomains; preload` (or some variant).

0 commit comments

Comments
 (0)