mg-code/yii2-url-manager

Useful url rules for url manager.

Installs: 7 257

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

1.0.0 2016-07-22 08:00 UTC

This package is auto-updated.

Last update: 2024-10-27 04:48:54 UTC


README

Useful url rules for url manager.

Install

Either run

$ php composer.phar require mg-code/yii2-url-manager "@dev"

or add

"mg-code/yii2-url-manager": "@dev"

to the require section of your composer.json file.

Usage

Once the extension is installed, you can use url rules:

HostUrlRule

Filters url rules by host name. Useful if your application works on multiple domains/subdomains.

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.

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.