Skip to content

✨ Add global 301 redirections (and 404 errors)

Compare
Choose a tag to compare
@lenybernard lenybernard released this 20 Dec 18:17
· 49 commits to 2.2 since this release
  • track and store in database every 404 errors
  • set a 301 redirection in the victoire interface

If it's not already done, please require and enable the Pagerfanta Bundle:

composer require "white-october/pagerfanta-bundle:^1.1"
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
        // ...
    );
}

Then update the schema, there is 2 new tables:

<?php

namespace AppBundle\DoctrineMigrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20171220215804 extends AbstractMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE vic_http_error (id INT AUTO_INCREMENT NOT NULL, redirection_id INT DEFAULT NULL, url VARCHAR(255) NOT NULL, error_message VARCHAR(255) NOT NULL, counter INT DEFAULT 1 NOT NULL, code INT NOT NULL, UNIQUE INDEX UNIQ_33D0AECAF47645AE (url), INDEX IDX_33D0AECA1DC0789A (redirection_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE vic_redirection (id INT AUTO_INCREMENT NOT NULL, link INT DEFAULT NULL, counter INT NOT NULL, url VARCHAR(255) DEFAULT NULL, dtype VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_65EBEF26F47645AE (url), INDEX IDX_65EBEF2636AC99F1 (link), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
        $this->addSql('ALTER TABLE vic_http_error ADD CONSTRAINT FK_33D0AECA1DC0789A FOREIGN KEY (redirection_id) REFERENCES vic_redirection (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE vic_redirection ADD CONSTRAINT FK_65EBEF2636AC99F1 FOREIGN KEY (link) REFERENCES vic_link (id) ON DELETE CASCADE');
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('ALTER TABLE vic_http_error DROP FOREIGN KEY FK_33D0AECA1DC0789A');
        $this->addSql('DROP TABLE vic_http_error');
        $this->addSql('DROP TABLE vic_redirection');
    }
}