diff --git a/src/CmsSeoComponent.php b/src/CmsSeoComponent.php index ab67da5..e3318bb 100644 --- a/src/CmsSeoComponent.php +++ b/src/CmsSeoComponent.php @@ -165,6 +165,10 @@ class CmsSeoComponent extends Component implements BootstrapInterface */ public $isRedirectNotFoundHttpException = true; + /** + * @var bool + */ + public $enableErrorPage=false; /** * Можно задать название и описание компонента @@ -180,7 +184,7 @@ static public function descriptorConfig() public function rules() { return ArrayHelper::merge(parent::rules(), [ - [['enableKeywordsGenerator', 'minKeywordLenth', 'maxKeywordsLength', 'activeContentElem', 'activeTree'], 'integer'], + [['enableKeywordsGenerator', 'minKeywordLenth', 'maxKeywordsLength', 'activeContentElem', 'activeTree', 'enableErrorPage'], 'integer'], ['robotsContent', 'string'], ['countersContent', 'string'], [['contentIds', 'treeTypeIds'], 'safe'], @@ -201,6 +205,7 @@ public function attributeLabels() 'contentIds' => \Yii::t('skeeks/cms', 'Elements of content'), 'sitemap_min_date' => \Yii::t('skeeks/seo', 'Минимальная дата обновления ссылки'), 'treeTypeIds' => \Yii::t('skeeks/seo', 'Types of tree'), + 'enableErrorPage' => \Yii::t('skeeks/seo', 'Show 404 page'), ]); } @@ -217,6 +222,7 @@ public function attributeHints() 'treeTypeIds' => \Yii::t('skeeks/seo', 'If nothing is selected, then all'), 'sitemap_min_date' => \Yii::t('skeeks/seo', 'Если будет задан этот параметр, то ни в одной ссылке не будет указано даты обновления меньше этой. Используется для переиндексации всех страниц.'), + 'enableErrorPage' => \Yii::t('skeeks/seo', 'If nothing is selected, then error page redirect to homepage'), ]); } @@ -260,6 +266,9 @@ public function renderConfigFormFields(ActiveForm $form) 'type' => \kartik\datecontrol\DateControl::FORMAT_DATE, ]); + $result .= $form->fieldSetEnd(); + $result .= $form->fieldSet(\Yii::t('skeeks/seo', 'Error page')); + $result .= $form->field($this, 'enableErrorPage')->checkbox(\Yii::$app->formatter->booleanFormat); $result .= $form->fieldSetEnd(); return $result; @@ -372,7 +381,7 @@ public function bootstrap($application) * Редирект 404 ошибок */ if (\Yii::$app->controller->uniqueId == 'cms/error') { - if (\Yii::$app->getErrorHandler()->exception instanceof NotFoundHttpException && $this->isRedirectNotFoundHttpException && !BackendComponent::getCurrent()) { + if (\Yii::$app->getErrorHandler()->exception instanceof NotFoundHttpException && $this->isRedirectNotFoundHttpException && !BackendComponent::getCurrent() && !\Yii::$app->seo->enableErrorPage) { \Yii::$app->response->redirect(Url::home()); \Yii::$app->response->getHeaders()->setDefault('X-Skeeks-Seo-Not-Found', "isRedirectNotFoundHttpException=true"); \Yii::$app->end(); diff --git a/src/messages/ru/main.php b/src/messages/ru/main.php index a24a2dc..4928ed5 100644 --- a/src/messages/ru/main.php +++ b/src/messages/ru/main.php @@ -6,6 +6,9 @@ 'Indexing' => 'Индексация', 'Codes counters' => 'Коды счетчиков', 'Sitemap settings' => 'Карта сайта', + 'Error page' => '404 страница', + 'Show 404 page' => 'Показывать 404 страницу', + 'If nothing is selected, then error page redirect to homepage' => 'Если галочки нет, несуществующие страницы перекидывают на главную страницу сайта', 'Types of tree' => 'Укажите типы разделов', 'Active flag to contents element' => 'Учитывать флаг активности для элементов контента', 'Active flag to tree' => 'Учитывать флаг активности для разделов',