Permalink
Browse files

[TASK] added 410 redirect option and 410 response page

  • Loading branch information...
Derrick Heesbeen Derrick Heesbeen
Derrick Heesbeen authored and Derrick Heesbeen committed Oct 20, 2017
1 parent 6cf1c31 commit d3332a4f43122f6532617ae57aab8f1d6380a512
@@ -0,0 +1,22 @@
<?php
namespace Experius\PageNotFound\Block\Response;
class Gone extends \Magento\Framework\View\Element\Template
{
protected function _prepareLayout()
{
$this->pageConfig->addBodyClass('410');
$this->pageConfig->getTitle()->set('410 Gone');
//$this->pageConfig->setKeywords();
//$this->pageConfig->setDescription();
$pageMainTitle = $this->getLayout()->getBlock('page.main.title');
$pageMainTitle->setPageTitle(__('Whoops, our bad...'));
return parent::_prepareLayout();
}
}
@@ -0,0 +1,41 @@
<?php
namespace Experius\PageNotFound\Controller\Response;
class Gone extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
/**
* Constructor
*
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Execute view action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$resultPage = $this->resultPageFactory->create();
$resultPage->setStatusHeader(410, '1.1', 'Gone');
$resultPage->setHeader('Status', '410 Gone');
return $resultPage;
}
}
@@ -76,7 +76,7 @@ protected function getRequest(){
return $this->request;
}
/* @return $action \Magento\Cms\Controller\Noroute\Index */
/* @return \Magento\Cms\Controller\Noroute\Index */
protected function getAction(){
return $this->action;
}
@@ -147,20 +147,27 @@ protected function urlHasParams($url){
return false;
}
protected function redirect($url, $code)
protected function redirect($url)
{
// add all configured params to redirect url. <included_params_redirect>
$queryStart = ($this->urlHasParams($url)) ? '&' : '?';
$params = (!empty($this->getParams(true))) ? $queryStart . $this->getParams(true) : '';
$url = $url . $params;
header("HTTP/1.1 301 Moved Permanently");
if($url=='410'){
$url = $this->url->getUrl('experius_pagenotfound/response/gone', ['_secure' => true]);
} else {
// add all configured params to redirect url. <included_params_redirect>
$queryStart = ($this->urlHasParams($url)) ? '&' : '?';
$params = (!empty($this->getParams(true))) ? $queryStart . $this->getParams(true) : '';
$url = $url . $params;
header("HTTP/1.1 301 Moved Permanently");
}
header("Location: " . $url);
exit();
$this->response->setRedirect($url,$code);
$this->getRequest()->setDispatched(true);
$this->getRequest()->setParam('no_cache', true);
return $this->actionFactory->create('Magento\Framework\App\Action\Redirect');
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="experius_pagenotfound" id="experius_pagenotfound">
<module name="Experius_PageNotFound"/>
</route>
</router>
</config>
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Experius\PageNotFound\Block\Response\Gone" name="response.gone" template="Experius_PageNotFound::response/gone.phtml"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,9 @@
<dl>
<dt><?php echo __('The page you requested was not found, and we have a fine guess why.'); ?></dt>
<dd>
<ul class="disc">
<li><?php echo __('If you typed the URL directly, please make sure the spelling is correct.'); ?></li>
<li><?php echo __('If you clicked on a link to get here, the link is outdated.'); ?></li>
</ul>
</dd>
</dl>

0 comments on commit d3332a4

Please sign in to comment.