繁体   English   中英

Symfony2:从HTTPS路由重定向到HTTP路由

[英]Symfony2: Redirecting from HTTPS-Route to HTTP-Route

我有基本路由"/"例如http://example.com ,如果有人致电https://example.com ,我想将此路由重定向到http 我做错了什么? 我是否必须将重定向选项放在其他位置? 谢谢!

在我的路由yml中,我有:

my_website:
    resource: "@MyWebsiteBundle/Controller/"
    type:     annotation
    prefix:   /
    defaults:
        route: home //<-- This is my name of the route "/" in my controller
        permanent: true

在您的routing.yml中:

home:
    path:     /
    defaults: { _controller: AcmeBundle:Default:index     }
    host: "www.example.com"
    schemes:  [http] # This is where the magic happens!

如果您需要所有路由,则可以使用另一种解决方案,可以转到security.yml并将access_control参数更改为:

access_control:
    - { path: ^/, roles: [IS_AUTHENTICATED_ANONYMOUSLY], requires_channel: http }

如果您需要https访问管理员:

access_control:
    - { path: ^/, roles: [IS_AUTHENTICATED_ANONYMOUSLY], requires_channel: http }
    - { path: ^/admin, roles: [ROLE_ADMIN], requires_channel: https }

可以在这里找到更多信息: http : //symfony.com/doc/current/book/security.html

尝试这个 :

my_website:
    resource: "@MyWebsiteBundle/Controller/"
    type:     annotation
    prefix:   /
    requirements:
        _scheme:  http

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM