3

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>
hisusu32
  • 437
  • 7
  • 22
  • https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules – Lex Li Nov 30 '20 at 22:45
  • In addition to enabling fail request tracing, you can also try use a computer as an agent, and then the mobile device sends a request through the computer. Then use tools like fidder to capture the request for analysis. – Bruce Zhang Dec 01 '20 at 08:40
  • Have the same issue, did you ever figure it out? – Allart Oct 04 '22 at 16:05

0 Answers0