yii2-url-manager
Useful url rules for url manager., (*1)
Install
Either run, (*2)
$ php composer.phar require mg-code/yii2-url-manager "@dev"
or add, (*3)
"mg-code/yii2-url-manager": "@dev"
to the require
section of your composer.json
file., (*4)
Usage
Once the extension is installed, you can use url rules:, (*5)
HostUrlRule
Filters url rules by host name.
Useful if your application works on multiple domains/subdomains., (*6)
return [
'class' => 'yii\web\UrlManager',
......
'rules' => [
['class' => 'mgcode\urlManager\HostUrlRule', 'host' => 'payment.example.com', 'rules' => [
['pattern' => '/', 'route' => '/payment/default/index'],
]],
]
];
RedirectUrlRule
Redirects user to destination route if current request matched.
Simply configure as any other url rule. You can specify statusCode, defaults to: 301., (*7)
return [
'class' => 'yii\web\UrlManager',
......
'rules' => [
['pattern' => '/some-old-link', 'route' => '/new/action', 'class' => 'mgcode\urlManager\RedirectUrlRule'],
]
];
See Yii Routing and URL Creation for more detail., (*8)