Heroku(PlayFramework/Scala)应用程序自动重定向到https [英] Heroku (PlayFramework/Scala) app automatically redirect to https

查看:72
本文介绍了Heroku(PlayFramework/Scala)应用程序自动重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Heroku上使用Scala开发的PlayFramework App;我只提到开发语言和框架,因为我发现的有关此问题的任何帖子都与PHP有关!我的HTTP和https在自定义域上运行,但是我想强制将HTTP请求重定向到https.

I have an PlayFramework App developed using Scala running on Heroku; I only mention the development language and framework because any posts I've found regarding this issue relate to PHP! I have http and https running on a custom domain but I would like to force http requests to be redirect to https.

我发现我需要使用以下内容更新.htaccess文件:

I've found that I need to update the .htaccess file with the following:

##Force SSL 

#Normal way (in case you need to deploy to NON-heroku)
RewriteCond %{HTTPS} !=on

#Heroku way
RewriteCond %{HTTP:X-Forwarded-Proto} !https 

#If neither above conditions are met, redirect to https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但是我不确定是否可以使用Play和Scala设置.htaccess文件.

But I am not sure if it is possible or how to set up the .htaccess file using Play and Scala.

请问有人可以建议吗?谢谢.

Please can someone advise? Thanks.

推荐答案

所有您需要做的就是添加

All you need to do is to add

play.filters.enabled += play.filters.https.RedirectHttpsFilter

在您的.conf文件中.

它将自动将所有HTTP请求重定向到HTTPS.

It will redirect all HTTP requests to HTTPS automatically.

默认情况下,它仅在production模式下工作.要更改它,请添加:

It only works in production mode by default. To change that, add :

play.filters.https.redirectEnabled = true

请参见 RedirectHttpsFilter 文档以获取更多信息.

See the RedirectHttpsFilter documentation for more.

这篇关于Heroku(PlayFramework/Scala)应用程序自动重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆