Reputation: 150198
I have an entry in Web.config under <system.webServer>
:
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.mydomain.com*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I expect that requests to http://www.mydomain.com
will be redirected to https://www.mydomain.com
. However, this is not happening.
Is there something wrong with the format of the rule? Must something else be done as well to enable the redirect?
This is running on a Windows 2012 machine under IIS 8. RewriteModule is listed under Modules for that website.
Upvotes: 1
Views: 48
Reputation: 7961
Make sure that the IIS Rewrite Module (installable using the Web Platform Installer is installed. Then, you can use IIS Manager to see, configure, and test the rewrite rules.
EDIT: I noticed you said you verified the module is installed. Cool! Most likely it's a problem with the rule itself. Use the testing tools provided by IIS to verify it works the way you expect.
EDIT 2: I think the problem with your rule was your match URL syntax. According to http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_pattern_syntax, the default syntax is ECMAScript regular expressions. That means if you want to match the .
character you'd have to use \.
.
Upvotes: 1
Reputation: 4496
remove "(.mydomain.com*)"
and set it to "(.*)"
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Upvotes: 1