The plus sign is one of the ways to encode a space in the URL. By the time the URL is passed to the UrlManager
's rules, it has already been decoded.
So if you open http://example.com/page/page+with+spaces
in your browser, the string passed to the rule will actually look like this: /page/page with spaces
.
This may or may not be what you want. The same URL can be expressed as http://example.com/page/page%20with%20spaces
, and that is usually the case with modern browsers.
If you really want to serve up some page in response to http://example.com/page/page+with+spaces
, add space to the list of valid characters for slug like so: 'page/<slug:[a-zA-Z \-]+>'
and then set your slug to page with spaces
.
Update:
Apparently, +
is a valid encoding for space character only in the query component of URL and should be treated literally in the path component (where you are trying to use it). However, and I've tested this right now, pluses do get replaced with spaces in yii\web\Request
, so my suggestion will work.
My advice is to avoid pluses in URLs, even though technically they are valid.