How to redirect from http to https in Angular 5?

I just built an Angular 5 project on the server. It works fine when I write the URL, but when I simply write or in the browser it won't redirect. Is there a file where I can modify this with some code? I'm using Windows server and it runs IIS. Thank you!

1 answer

  • answered 2018-01-10 21:35 Neyxo

    You need to configure this in your IIS configuration and not inside your Angular code, since it is a URL rewrite and not a duplication of the Website.

    Either you configure it with an web.config file:

    <?xml version="1.0" encoding="UTF-8"?>
                    <clear />
                    <rule name="Redirect to https" stopProcessing="true">
                        <match url=".*" />
                            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                        <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />

    If you don't know how to use IIS configuration files i can recommend you to read the Microsoft documentation.

    Or you could use a Tool like described in this Microsoft Blog (Maybe a little bit easier, because it has a GUI, however you will have to reconfigure it each time you move to a different server):