General Regex For Url Routing

I have an issue with URL routing and am not sure if Yii is capable of achieving what I want. We have users coming in on old (and malformed) urls such as:




I currently have a rule in the urlManager config as such:

'this-is-a-page' => 'contentPage/index/src/37'

which works fine for visits to:


but not for



Is it possible to write general rule to capture these cases? I have tried:

'this-is-a-page*' => 'contentPage/index/src/37'


'this-is-a-page<\w+>' => 'contentPage/index/src/37'

But they do not seem to work as I would expect.

Thanks for any help

If you don’t need to capture the extra parameters, try:

'this-is-a-page.*' => 'contentPage/index/src/37'


'this-is-a-page<.*>' => 'contentPage/index/src/37'

I think the first is the correct one.

We don’t need the extra params, unfortunately neither of those seem to work. We are using:


Will that make the solution any different?

This is my urlManager code in full:




        'this-is-a-page<.*>' => 'contentPage/index/src/37',



going to url:


and getting the error:

Unable to resolve the request "this-is-a-page"

Make sure you haven’t got another entry for urlManager defined in your config array.

That is the only entry for urlManager in the config array

Try this:

'this-is-a-page<rest:.*>' => 'contentPage/index/src/37',

Great, that worked! Thanks :)

I have to do the following generate a

$v2ApiList = array(

$v2Regex = ‘(’;

foreach ($v2ApiList as $index=>$v2Api) {
$v2Regex = $v2Regex . ‘|’;
$v2Regex = $v2Regex . ‘\b’ . $v2Api . ‘\b’;

$v2Regex = $v2Regex . ‘)’;

‘rules’ => array(

‘service/v2/<controller:(?!’ . $v2ApiRegex . ‘)\w+>/<action:\w+>’ => ‘service/<controller>/<action>’,

‘service/v2/<controller:’ . $v2ApiRegex . ‘>/<action:\w+>’ => ‘service/v2/v2<controller>/<action>’)

this is to generate

‘service/v2/<controller:(?!(\banc\b|\bdef\b=))\w+>/<action:\w+>’ => ‘service/<controller>/<action>’,


‘service/v2/<controller:(\babc\b|\def\b)>/<action:\w+>’ => ‘service/v2/v2<controller>/<action>’ — this is going to

‘service/v2/<controller:(\babc\b|\def\b)>/<action:\w+>’ => ‘service/v2/v2<controller>/<action>’

instead it should go to

‘service/v2/<controller:(?!(\banc\b|\bdef\b=))\w+>/<action:\w+>’ => ‘service/<controller>/<action>’,

Please let me know how we can generate proper url set with dynamic regex