我試圖強制https和www前綴。然而,我的規則並沒有完全奏效。這是我的原則:Web.config URL重寫 - 強制www前綴和https
<rewrite>
<rules>
<clear />
<rule name="Force https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.mydomain.co.uk/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Force www" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
<add input="{HTTP_HOST}" pattern="www.mydomain.co.uk" negate="true" />
</conditions>
<action type="Redirect" url="https://www.mydomain.co.uk/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
- 它適用於HTTP重定向到https。
- 如果我去https://mydomain.co.uk它的工作原理(重定向到https://www.mydomain.co.uk)
- 但是如果我去https://mydomain.co.uk/blah/whatever
請可有人建議它不工作?謝謝。
由於後來的處理也沒關係。爲什麼使用'stopProcessing =「true」'?這不妨礙以下規則的處理嗎? –
是的。 「_A規則可能會打開StopProcessing標誌,當此標誌打開時,這意味着不會再處理後續規則,並且由此規則生成的URL將傳遞到IIS請求管道(如果規則匹配)。默認情況下,此標誌已關閉._「請參閱https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference – VDWWD
但這意味着如果請求缺少WWW前綴和HTTPS協議。 WWW前綴將被添加,但HTTPS不會因爲沒有更多的規則被處理。 –