Skip to content

Commit c4d658d

Browse files
authored
Merge pull request #587 from magefan/11205-Automatic-Redirects-Issue-V2
Tag Auto Redirect
2 parents 320f8f2 + e0d5b83 commit c4d658d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Controller/Tag/View.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace Magefan\Blog\Controller\Tag;
99

10+
use Magento\Framework\App\Action\Context;
1011
use Magento\Store\Model\ScopeInterface;
1112

1213
/**
@@ -21,6 +22,19 @@ class View extends \Magefan\Blog\App\Action\Action
2122
*/
2223
private $_storeManager;
2324

25+
/**
26+
* @var \Magefan\Blog\Model\Url
27+
*/
28+
protected $url;
29+
30+
public function __construct(
31+
Context $context,
32+
\Magefan\Blog\Model\Url $url = null
33+
) {
34+
parent::__construct($context);
35+
$this->url = $url ?: $this->_objectManager->get(\Magefan\Blog\Model\Url::class);
36+
}
37+
2438
/**
2539
* View blog author action
2640
*
@@ -34,7 +48,10 @@ public function execute()
3448

3549
$tag = $this->_initTag();
3650
if (!$tag) {
37-
return $this->_forwardNoroute();
51+
$resultRedirect = $this->resultRedirectFactory->create();
52+
$resultRedirect->setHttpResponseCode(301);
53+
$resultRedirect->setPath($this->url->getBaseUrl());
54+
return $resultRedirect;
3855
}
3956

4057
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('current_blog_tag', $tag);

0 commit comments

Comments
 (0)