I've these two rules in my web config file to force https and remove www from url.
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(https?://)?www\.(.+)$" />
</conditions>
<action type="Redirect" url="{C:1}{C:2}" redirectType="Permanent" appendQueryString="false"/>
</rule>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{R:1}" redirectType="Found" appendQueryString="false" />
</rule>
Note: I've gone through almost all the questions here on SO and almost all the blogs but no luck yet :(. Some of the SO posts are as;
Proper method to remove www from address using IIS URL Rewrite
URL Rewrite Remove WWW From HTTPS
http://madskristensen.net/post/url-rewrite-and-the-www-subdomain
http://www.serverintellect.com/support/iis/url-rewrite-to-redirect-www-iis7/
http://www.bradymoritz.com/iis7-url-rewrite-remove-www-from-all-urls/
....
Make sure you are putting your rules in the web.config under system.webServer - > rewrite -> rules.
This should do the job for you:
<system.webServer>
<rewrite>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="Off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{CACHE_URL}" pattern="*://www.*" />
</conditions>
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
</rule>
<rewrite>
</system.webServer>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.