I need to require a domain name in my symfony routing, my route looks like the following:
domain_example:
url: /routing/example/:domain_name
param: { module: myModule, action: index, sf_format: json }
requirements: { domain_name: '/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/' }
I have also tried:
requirements: { domain_name: '[/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/]' }
If I call my route like so: mydomain.com/routing/example/otherdomain.com
- I just get the module/action does not exist exception.
To summarize
dot are used as segment separator in Symfony. So you should add this option to your route to force Symfony to only use /
as separator:
options:
segment_separators: [/]
Next, your regex is wrong, but SO has one for you:
[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?
Your final route:
domain_example:
url: /routing/example/:domain_name
param:
module: main
action: index
sf_format: json
requirements:
domain_name: '[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?'
options:
segment_separators: [/]