Mecha CMS

Mecha CMS blog and documentation.

Relative URL

Updated: Sunday, 07 August 2016

Change absolute URL to relative URL in the HTML output.

Update: This feature has been added in Mecha version 1.2.0 as a part of the minify plugin option.

Some people consider it as a best-practice to use relative URL, so that your cached page will not be bound to the base URL of where it is currently deployed. For example, it will be able to work on localhost, as well as on your public domain, without modifications. This will also slightly reduce the page size.

Filter::add('shield:input', function($content) use($config) {
    $url = $config->protocol . $config->host;
    return str_replace(
        array(
            '="' . $url . '"',
            '="' . $url . '/',
            '="' . $url . '?',
            '="' . $url . '#'
        ),
        array(
            '="/"',
            '="/',
            '="?',
            '="#'
        ),
    $content);
});
Donation and Email Subscription