How to add, replace or remove Middleware

This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
Oct 4, 2019
By hissy for Developers

HTTP middlewares are configured in concrete/config/app.php

    'middleware' => [
        [
            'priority' => 1,
            'class' => \Concrete\Core\Http\Middleware\ApplicationMiddleware::class,
        ],
        'core_cookie' => \Concrete\Core\Http\Middleware\CookieMiddleware::class,
        'core_xframeoptions' => \Concrete\Core\Http\Middleware\FrameOptionsMiddleware::class,
        'core_thumbnails' => '\Concrete\Core\Http\Middleware\ThumbnailMiddleware',
    ],

You can add your own middleware by overriding config value from application/config/app.php. Of course, you can change the class too.

return [
    'middleware' => [
        'core_cookie' => \Application\Concrete\Http\Middleware\MyCustomizedCookieMiddleware::class,
        'my_great_middleware' => \Application\Concrete\Http\Middleware\MyGreatMiddleware::class,
    ],
];

If you want to remove a core middleware, you need to create a passthru middleware.

return [
    'middleware' => [
        'core_xframeoptions' => \Application\Concrete\Http\Middleware\PassThruMiddleware::class,
    ],
];
<?php
namespace Application\Concrete\Http\Middleware;

use Concrete\Core\Http\Middleware\DelegateInterface;
use Concrete\Core\Http\Middleware\MiddlewareInterface;
use Symfony\Component\HttpFoundation\Request;

class PassThruMiddleware implements MiddlewareInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(Request $request, DelegateInterface $frame)
    {
        // PassThru
        return $frame->next($request);
    }
}
Recent Tutorials
Restoring deleted pages using advanced search
Jan 16, 2025
By myq.

How to recover deleted pages when there are more than a few to choose from.

How to Automate the Copyright Year
Dec 27, 2024

Learn how to keep your website's copyright year updated automatically in Concrete CMS.

How to change the path of a group of pages
Dec 23, 2024
By myq.

Change the canonical path without breaking things

Bi-directional Express associations
Dec 18, 2024
By myq.

Set up associations between Express entries in both directions

Display Express Data Across Multiple Sites
Dec 17, 2024
By myq.

A guide to configuring Express entities and the Express Entry List block to ensure proper data display across multiple sites.

Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Improvements?

Let us know by posting here.