Skip to content
Roger Hughes edited this page Jun 16, 2021 · 1 revision

Divert is a high performance way of implementing page redirects in Expressionengine.

Use if:

You can't/don't want to edit your htaccess/vhost/NGINX (honestly, this is the fastest way to do a redirect).

More

Add this to the top of index.php to bypass all EE code for the fastest performance:

// START DIVERT
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    $p = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'divert_settings';
    if (file_exists($p . DIRECTORY_SEPARATOR . 'redirections')) {
    	$r = file_get_contents($p . DIRECTORY_SEPARATOR . 'redirections');
        $l = explode(PHP_EOL, $r);
        foreach ($l as $_l) {
            $r = explode(' ', $_l);
            if (count($r) == 3) {
                if ($_SERVER['REQUEST_URI'] == $r[1]) {
                    header('Location: ' . $r[2], true, $r[0]);
                    die();
                }
            }
        }
    }
}
// END DIVERT

Changelog

1.0.0 - 2019-07-16

  • initial release

Credits

Icon by turkkub from Flaticon is licensed by CC 3.0 BY

Clone this wiki locally