Prevent content duplicate

Hi, dear colleagues.

Is it possible prevent duplication content for increase Google ranging? I mean similar pages with different URL. For example, http:_//_site.com/vacancy and http:_//_site.com/vacancy/. Obviously, routes are absolutely similar.

Do you know how to implement automatically redirect from http:_//_site.com/vacancy to http:_//_site.com/vacancy/ with header 301?

P.S. Dear moderators, sorry for creating new topic, if such thread already exists.

For redirect you can use this snippet in .htaccess file:




RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$

RewriteRule ^(.*[^/])$ $1/ [L,R=301]






RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$

RewriteRule ^(.*[^/])$ $1/ [L,R=301]



Unfortunately, shuch snippet doesn’t works in Yii2, because Yii2 already use Rewrite Conditions in Input Point.

Давайте по-русски :)

Странно, потому что у меня всё работает. Кладёте всё это в .htaccess файл, а сам файл кладёт не в корень приложения, а в директорию web.

Попробую ещё раз. Создам на русском форуме аналогичную тему. Мне казалось что надо где-то в базовом контроллере фильтры использовать.

Dear PendalF, thank you for your help. Now it works fine. There is the solution:

.htaccess file




AddDefaultCharset UTF-8


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$

RewriteRule ^(.*[^/])$ $1/ [L,R=301]


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



And in my config:

/config/web.php file:




'urlManager' => [

            'enablePrettyUrl' => true,

            'showScriptName'  => false,

            'rules'           => require(__DIR__ . '/routes.php'), // some my Router rules here

            'suffix'          => '/',

        ],



I hope, this solution will help somebody.