I'm trying to set rules on IIS to redirect to HTTPS if the user enters the site through HTTP. Right now my current code redirects to HTTPS if the user browses the site via desktop computer. However when accessing my website via HTTP on any mobile phone, it simply just times out.
Below is how my current web.config
file looks:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<httpRedirect enabled="false" destination="https://mywebsitehere.com" />
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://mywebsitehere.com/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
At first I tried doing HTTP redirect in IIS but it would time out and say too many redirects. When I did URL Rewrite
it worked for browser, but again not for mobile.
I tried adding something like this, but that didn't work either:
<rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="http://mysite.mobi" appendQueryString="false" redirectType="Found" />
</rule>