简体   繁体   中英

How to force symfony2 to use HTTPS only for one page

I have to use HTTPS for only single page in symfony2 app. I've tried like

security.yml

- { path: ^/payment, roles: ROLE_USER, requires_channel: https } 

It works good but when i navigate to other pages from /payment page its stays same in HTTPS instead of HTTP. I've also tried something from sonata admin controller like:

PaymentAdmin.php

$collection
        ->add('makePayment', 'payment/{paymentId}',$options = array('_scheme' => 'https'));

but the same problem.simply i just want to use HTTPS only for /payment page not for other pages.how can i solve this issue.

You could try adding regexp start notation "^" to your path like this "^/payment" which should state that routes which start with /payment should be in "https".

{ path: ^/payment, roles: ROLE_USER, requires_channel: https } 

The example in http://symfony.com/doc/current/cookbook/security/force_https.html also shows that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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