I have an Angular 2 app that I only want to run on https. What is the best way to redirect addresses that use http to use https instead?
Asked
Active
Viewed 8,577 times
6
-
Where is your App hosted? – Piyush Patil Jul 12 '16 at 18:00
-
Its in Azure as a web application. – Ben Cameron Jul 12 '16 at 18:01
-
Are you using Apache Linux or some thing else? – Piyush Patil Jul 12 '16 at 18:02
-
IIS I believe is the default in Azure. – Ben Cameron Jul 12 '16 at 18:03
3 Answers
5
I have added a web.config to the Angular2 site which contains the below. Remember that this is for an IIS hosted application. All addresses are now redirected the https version.
<?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>

Ben Cameron
- 4,335
- 6
- 51
- 77
-
-
-
OK. It wasn't working because I didn't have URL rewrite installed on my server. After getting it installed in combination with this rule it was working. Thanks. – Kevin Quiring Mar 29 '17 at 16:57
-
1I have similar situation but for me the application is created through Angular -cli. so I cannot this file explicitly. And Azure is the server in my case. Any solution? – indra257 Apr 03 '17 at 20:59
-
0
As per your question you will have to force https for you domain from the server side. As you mentioned IIS in your comment here are some of the ways that you can achieve force HTTps.

Piyush Patil
- 14,512
- 6
- 35
- 54
0
I have to write in an exception rule for the web api service based on where the web api was located within same area :/
Notice this line
<add input="{REQUEST_URI}" pattern="^/(C2NGService)" negate="true" />
web.config for angular 5
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(C2NGService)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Tom Stickel
- 19,633
- 6
- 111
- 113