I want :
/p/{name} ==> in public access
/profile ==> in loggin access
I did this in security.yml
access_control:
- { path: ^/[p]/* , role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/*, role: ROLE_CONNECT }
But, when I browse :
/profile => accessible in public ==> KO
/p/name-here => accessible in public ==> OK
I'm pretty sure that ^/[p]/*
is going to match any path that starts with /p
, and you have it as the first rule, so it matches first and allows access.
The square brackets []
are defining a set of characters to match, you only want to match one so you don't need them. The *
says to match zero or more /
characters at the end, you know there will be one /
after p
so omit the star. The path is a prefix so you don't need to worry about the variable part of the path.
Try this:
- { path: ^/p/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/profile, role: ROLE_CONNECT }
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.