1
1
.. index ::
2
2
single: Routing; Allow / in route parameter
3
3
4
- How to allow / character in a route parameter
5
- =============================================
4
+ How to allow a "/" character in a route parameter
5
+ =================================================
6
6
7
7
Sometimes, you need to compose URLs with parameters that can contain a slash
8
- ``/ ``. But Symfony uses this character as separator between route parts.
8
+ ``/ ``. For example, take the classic ``/hello/{name} `` route. By default,
9
+ ``/hello/Fabien `` will match this route but not ``/hello/Fabien/Kris ``. This
10
+ is because Symfony uses this character as separator between route parts.
9
11
10
- Configure the route
12
+ This guide covers how you can modify a route so that ``/hello/Fabien/Kris ``
13
+ matches the ``/hello/{name} `` route, where ``{name} `` equals ``Fabien/Kris ``.
14
+
15
+ Configure the Route
11
16
-------------------
12
17
13
18
By default, the symfony routing components requires that the parameters
14
19
match the following regex pattern: ``[^/]+ ``. This means that all characters
15
- are allowed excepted ``/ ``.
20
+ are allowed except ``/ ``.
16
21
17
- You must explicitely allow ``/ `` to be part of your parameter specifying
22
+ You must explicitly allow ``/ `` to be part of your parameter by specifying
18
23
a more permissive regex pattern.
19
24
20
25
.. configuration-block ::
@@ -55,7 +60,7 @@ a more permissive regex pattern.
55
60
56
61
return $collection;
57
62
58
- .. code-block :: annotation
63
+ .. code-block :: php-annotations
59
64
60
65
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
61
66
@@ -68,4 +73,6 @@ a more permissive regex pattern.
68
73
{
69
74
// ...
70
75
}
71
- }
76
+ }
77
+
78
+ That's it! Now, the ``{name} `` parameter can contain the ``/ `` character.
0 commit comments