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?
HSTS is a security feature that forces the browser to use HTTPS even when accessing an HTTP URL. The browser will start using HSTS for a domain after receiving a Strict-Transport-Security header from the server. The browser also ships with a list of domains for which HSTS is enabled by default.
Migrating your site from HTTP to HTTPS can seem like an overwhelming and complex process. However, with big security benefits and SEO advantages, it makes sense to migrate from HTTP to HTTPS. The process needn't be difficult either. The key is to migrate using 301 to redirect HTTP to HTTPS.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With