skeeks/yii2-external-links AutoCorrect external links after rendering html page

AutoCorrect external links after rendering html page

  1. Installation
  2. How to use (simple)
  3. How to use (advanced)
  4. Redirect page security
  5. Screenshot

Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist skeeks/yii2-external-links "*"

or add

"skeeks/yii2-external-links": "*"

How to use (simple)

//App config
[
    'bootstrap'    => ['externalLinks'],

    'components'    =>
    [
        //....
        'externalLinks' =>
        [
            'class' => 'skeeks\yii2\externalLinks\ExternalLinksComponent',
        ],
        //....
    ],

    'modules'    =>
    [
        //....
        'externallinks' =>
        [
            'class' => 'skeeks\yii2\externalLinks\ExternalLinksModule',
        ],
        //....
    ]
]

How to use (advanced)

//App config
[
    'bootstrap'    => ['externalLinks'],

    'components'    =>
    [
        //....
        'externalLinks' =>
        [
            'class' => 'skeeks\yii2\externalLinks\ExternalLinksComponent',

            //Additional
            'enabled'                           => true,
            'noReplaceLocalDomain'              => true,
            'backendRoute'                      => '/externallinks/redirect/redirect',
            'backendRouteParam'                 => 'url',
            'enabledB64Encode'                  => true,
            'noReplaceLinksOnDomains'           => [
                'site1.ru',
                'www.site1.ru',
                'site2.ru',
            ],
        ],
        
        'urlManager' => 
        [
            'rules' => 
            [
                //Rewriting the standard route
                '~skeeks-redirect'                        => '/externallinks/redirect/redirect',
            ]
        ]
        //....
    ],

    'modules'    =>
    [
        //....
        'externallinks' =>
        [
            'class' => 'skeeks\yii2\externalLinks\ExternalLinksModule',
        ],
        //....
    ]
]

Redirect page security

  • Only absolute links with a scheme from allowedSchemes (http, https by default) are accepted; anything else gets 400.
  • Links replaced on the page are signed: createRedirectUrl($url) adds the signParam (sign) parameter, an HMAC of the link with signKey (the request cookieValidationKey by default). Signed links are opened automatically.
  • Unsigned or wrongly signed links (old caches, search engines, links made by somebody else) are not opened automatically: the page shows the target address and a "go" button.
  • The page is sent with X-Robots-Tag: noindex, nofollow and the robots meta tag. Do not disallow it in robots.txt, otherwise search engines cannot see noindex.

Screenshot

SkeekS CMS admin panel

skeeks!
SkeekS CMS (Yii2) — quickly, easily and effectively!
skeeks.com | cms.skeeks.com