7

You can always return \Magento\Framework\Controller\Result\Raw with custom status header. Also you can send 404 by throwing \Magento\Framework\Exception\NotFoundException. It will be processed in lib/internal/Magento/Framework/App/FrontController.php:61 to 'noroute' path, which will resolve to \Magento\Cms\Controller\Noroute\Index (or more specific if ...


3

This is implemented in the Mage2 Module Experius PageNotFound which can be found on Github https://github.com/experius/Magento-2-Module-PageNotFound For more information see the following commit https://github.com/experius/Magento-2-Module-PageNotFound/commit/d3332a4f43122f6532617ae57aab8f1d6380a512#diff-6c0df54a0adc7658411e157ba9feaf3a additional ...


2

As suggested by @Anton Kril, this worked for me. namespace Company\ModuleName\Controller\Index; use Magento\Framework\App\Action\Context; use \Magento\Framework\Exception\NotFoundException; class Index extends \Magento\Framework\App\Action\Action { public function execute() { throw new NotFoundException(__('Some Exception message.')); ...


2

If you look in vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor Line 85 onwards: $response = $this->_responseFactory->create(); $response->setRedirect($redirectUrl, $redirectCode); $response->setNoCacheHeaders(); return $response; That may help. Good luck!


2

You need to modify getValue method. Try following way: app/code/SR/MagentoCommunity/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\App\Response\HeaderProvider\XssProtection">...


2

You shouldn't be modifying the response code with in a block, it should be in the controller. Your block should only contain logic that is used within template files to format data etc. But in your controller to return a 404 you can use the following after injecting the resultForwardFactory \Magento\Framework\Controller\Result\ForwardFactory return $this-&...


1

As discussed if this is not your case then you can use ob_start for output buffering <?php ob_start(); // code ob_end_flush(); ?>


1

I tried a few different versions of setHeader() but the only thing that worked for me was overwriting XFrameOptions. Vendor/Module/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">...


1

Well, The problem is to change the value of the HEADER_ENABLED to 0 because it conflicts with CloudFlare. To achieve this you need to edit this value manually in this core files and this is a very bad way to do this. So Magento Support overriding Methods by creating a plugin. Plugin, as Magento defines, is A plugin, or interceptor, is a class that ...


1

Just check registration.php file on UTF-8 BOM elements. This a symbol on the start of file what can be seen without special mode in editors.


1

Open .htacces in magento 1 root file and find 'X-XSS' you get below line Header set X-XSS-Protection: "1; mode=block" env=!ie8 assigne '#' befrore this line


1

I think you first you need to clear header you can inject this dependency into your __construct Magento\Framework\HTTP\PhpEnvironment\Response and then clear header using clearHeader($name) method and then add header by using this code $header->getHeaders()->addHeaderLine($name, $value); you can find this code sample in this class only


Only top voted, non community-wiki answers of a minimum length are eligible