我正在使用symfony 3.4。我在security.yml文件中有一个路由,更具体地说是在access_control
密钥中。路线是这样的:
- { path: '^/route/subroute/SOME_TOKEN', roles: [ SOME_ROLE ] }
SOME_TOKEN
是一个urlencoded字符串,除了未知数量的其他字符外,可能包含也可能不包含正斜杠。
根据文档说here我的路线看起来应该是这样的:
- { path: '^/route/subroute/.+', roles: [ SOME_ROLE ] }
它给了我404: Route not found.
。请注意我正在使用启用了AllowEncodedSlashes
选项的Apache2。
我的猜测是我根本不知道如何正确编写正则表达式。由于我对正则表达式也不好,这对我来说并不会让人感到意外。
我尝试了不同的变化。例如(.+)
,[.+]
等。
# bin/console --env=dev debug:router | grep "/customer/unsubscribe/anon/"
customer_communication_preferences_unsubscribe_anon ANY https ANY /customer/unsubscribe/anon/{hash}
路线定义:
customer_communication_preferences_unsubscribe_anon:
path: /customer/unsubscribe/anon/{hash}
defaults: { _controller: PizokelCustomerBundle:Communication:unsubscribeAnonCustomer }
schemes: ['%routing.scheme.my_account%']
在您的路线定义中,您并不是说hash
可能是任何角色。
试试这个 :
customer_communication_preferences_unsubscribe_anon:
path: /customer/unsubscribe/anon/{hash}
defaults: { _controller: PizokelCustomerBundle:Communication:unsubscribeAnonCustomer }
schemes: ['%routing.scheme.my_account%']
requirements:
hash: .+