Can Heroku force an application to use SSL/TLS?

Issue

You have configured an SSL endpoint and now you want your application to use https for all requests.

Resolution

Redirects need to be performed at the application level as the Heroku router does not provide this functionality. You should code the redirect logic into your application.

Under the hood, Heroku router (over)writes the X-Forwarded-Proto and the X-Forwarded-Port request headers. The app checks X-Forwarded-Proto and respond with a redirect response when it is not https but http.

Rails

Use config.force_ssl = true in your config/environments/production.rb or similar.

Node (Express.js)

Use a package to set this up for your app. Some options can be found here: https://www.npmjs.com/search?q=express+ssl

PHP

You can add directives to the .htaccess file at the root of your project to do this. See this SO post for an example https://stackoverflow.com/a/34065445

Django

Set SECURE_SSL_REDIRECT to True.

Flask

You can use https://github.com/kennethreitz/flask-sslify to handle this for you.

Source: https://help.heroku.com/J2R1S4T8/can-heroku-force-an-application-to-use-ssl-tls