Modx Header Response

Is there a way to overwrite the header response in modrequest.class.php? I tried adding a custom response from .htaccess. But it’s actually displaying the responses twice. The one from the htacess and also the one from the PHP file. What’s the correct way to disable the Modx one.

.htaccess:
Header set x-powered-by "Company Name"

modrequest.class.php

 // If enabled, send the X-Powered-By header to identify this site as running MODX, per discussion in #12882
        if ($this->modx->getOption('send_poweredby_header', null, true)) {
            $version = $this->modx->getVersionData();
            header("X-Powered-By: MODX {$version['code_name']}");
        }

I don’t just want to directly write on the core file if there’s a different way of doing it.

Thanks,

K

You can write a plugin in OnWebPagePrerender that adds a custom header.

https://docs.modx.com/3.x/en/extending-modx/plugins

Thanks Jako. Just read this RFC: Adding optional “X-Powered-By: MODX Revolution” header to MODX sites? #12882 My question would be, is there an easier way to disable this from /manager instead of writing a plugin?

To disable the default MODX X-Powered-By header, you just have to disable the send_poweredby_header MODX system setting. If that setting does not exist, you have to create it and set it to 0.

1 Like

Great! Thanks! This is what I was looking for :smiley: