Running on Windows Azure Websites, I want to use ssl via the default *.azurewebsites.net certificate. It works without doing anything, but http is also available for every destination, not just https. How do I force a redirect from http to https? Normally I could just do something like:
var https = require('https');
...
var options = {
key: fs.readFileSync('path.key'),
cert: fs.readFileSync('path.crt')
};
...
https.createServer(options, app)
but since I don't know anything about the *.azurewebsites.net certificate, such as its path, that's not going to work.
How do I redirect all or some requests to https?
In web.config
, add the following rule before any other rule that has stopProcessing="true"
.
<rule name="RedirecttoHTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
You can also just use the normal http.createServer(app)
for production if you want to the *.azurewebsite.net wildcard certificate.
References:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments