【发布时间】:2014-06-30 12:35:22
【问题描述】:
问题:
- 用户使用https://example.com/login 登录
- 身份验证已获批准
- 根据 security.yml 中的配置,Symfony2 在登录后将用户重定向到个人资料页面。
- 但它会将他们重定向到错误的网址http://example.com/homepage
security.yml:
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
main:
pattern: ^/
form_login:
check_path: /login_check
login_path: /login
default_target_path: /profile
provider: fos_userbundle
logout:
path: /logout
target: /splash
anonymous: ~
access_control:
- { roles: ROLE_USER, requires_channel: https }
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
acl:
connection: default
环境架构:
Server1 和 Server2 拥有 Symfony2 应用程序。
问题:
如何强制 Symfony 使用 https 协议而不是 http 生成重定向 URL?
到目前为止,我已经查看了这些文档,但解决方案在我的情况下不起作用:
【问题讨论】:
-
你的routing.yml中有方案:[https]吗?
-
也试过了,谢谢回复。最初这会导致无限重定向,然后我将trusted_proxies:[10.0.0.0/8] 添加到config.yml 中。无限重定向现在消失了,但 Symfony 仍然生成重定向 URL 为 http 而不是 https。谢谢
-
我在 AWS 有这个确切的架构。不知道为什么你的不工作。如果用户只是点击
example.com/login,他们是否会重定向到https? -
这也适用于下游部署在 Heroku 上的应用程序。
标签: php .htaccess symfony redirect amazon-elb