3

I have a react web application that I'm hosting on a Windows Server.

In IIS I created URL Rewrite rules. When I view the website from within our network the rewrite rules work and it redirects from HTTP to HTTPS.

However since port 80 is closed on the public side when i try to view the website in HTTP it never redirects and just times out. I'm assuming that's because it never actually hits the page since the port is closed so the redirect never kicks in.

Is there a way to still get the website to redirect to HTTPS with that port closed?

Here is how my 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>
JImmy G
  • 149
  • 3
  • 12

1 Answers1

3

The answer is No, in order for any form of HTTP redirection to work within the server, the server must be capable of getting the incoming connection HTTP request on port 80, It would then send a 3xx response to tell the browser to try again with a different URL, That URL would be an HTTPS URL. If the HTTP request is closed before the server gets it, naturally it can't do anything.

samwu
  • 3,857
  • 3
  • 11
  • 25
  • That is so lame but you are right. It makes sense if you think about it. If a redirect is needed & you don't want port 80 open I guess that requires an nginx or L5 solution to achieve that. – drzounds May 05 '22 at 01:06