agence-adeliom/easy-redirect-bundle

Symfony redirection bundle for EasyAdmin

1.0.0 2021-10-06 14:50 UTC

This package is auto-updated.

Last update: 2021-11-08 08:30:58 UTC


README

Adeliom Quality gate

Easy Redirect Bundle

This bundle adds entities for redirects and 404 errors.

For redirects, 404 errors are intercepted and the requested path is looked up. If a match is found it redirects to the found redirect's destination. The count and last accessed date are updated as well. A redirect form type and validation is available as well.

404 errors can be logged as well. Each 404 error is it's own record in the database. The path, full URL, timestamp, and referer are stored. Storing each error as a separate record allows viewing statistics over time and seeing all the referer URLs. When a redirect is created or updated, 404 records that match it's path are deleted.

Installation

Install with composer

composer require agence-adeliom/easy-redirect-bundle

Setup database

Using doctrine migrations

php bin/console doctrine:migration:diff
php bin/console doctrine:migration:migrate

Without

php bin/console doctrine:schema:update --force

Documentation

Manage redirect in your Easyadmin dashboard

Go to your dashboard controller, example : src/Controller/Admin/DashboardController.php

<?php

namespace App\Controller\Admin;

...
use Adeliom\EasyRedirectBundle\Admin\EasyRedirectTrait;

class DashboardController extends AbstractDashboardController
{
    ...
    use EasyRedirectTrait;

    ...
    public function configureMenuItems(): iterable
    {
        ...
        yield from $this->configRedirectEntry();

        ...

Configuration

# config/packages/easy_redirect.yaml
easy_redirect:
    redirect_class:     ~ # Required and must be an instance of "Adeliom\EasyRedirectBundle\Entity\Redirect"
    not_found_class:    ~ # Required and must be an instance of "Adeliom\EasyRedirectBundle\Entity\NotFound"
    model_manager_name: ~ # If a custom model manager is used by default its 'default'

    # When enabled, when a redirect is updated or created, the NotFound entites with a matching path are removed.
    remove_not_founds: true

License

MIT

Authors

Thanks to

kbond/ZenstruckRedirectBundle