Reputation: 137
I built an Angular 5 project. It works fine when I write the URL https://www.example.com/, but when I simply write www.example.com or http://example.com in the browser it won't redirect. Is there a file where I can make the URL always redirect to https://www.example.com? I'm using a Windows server and it runs IIS. Thank you!
Upvotes: 2
Views: 12830
Reputation: 730
You need to configure this in your IIS (Internet Information Service) 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"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
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):
Upvotes: 2