duanming0494 2015-05-21 14:34
浏览 57

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

I have the base route "/" like http://example.com and I want to redirect this route to http if someone calls https://example.com. What I am doing wrong? Do I have to put the redirect option somewhere else? THANKS!

In my routing yml I have:

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

2条回答 默认 最新

  • duanpoqiu0919 2015-05-21 14:45
    关注

    In your routing.yml:

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

    An alternate solution if you want ALL routes you can go to your security.yml and change the access_control parameter to this :

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

    If you ever need https to access an admin :

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

    More information can be found here : http://symfony.com/doc/current/book/security.html

    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染