miranj/craft-redirector

A Craft CMS plugin for redirecting URLs to entries.

dev-dev 2024-12-20 20:34 UTC

This package is auto-updated.

Last update: 2024-12-20 20:35:20 UTC


README

A Craft CMS plugin for handling legacy paths and URLs by preventing 404s and redirecting to the new entry's URL.

Contents

Usage

In order to handle legacy paths and URLs, we need to create a field to capture them. We can make use of Craft's built-in URL field for this purpose.

  1. Create a new field of type URL. Set the Allowed URL Types to Web Page.

  2. Add this field to all sections where entries have URLs of their own.

  3. Create a config file for this plugin config/redirector.php and add the handle of the field created in the first step.

    <?php
    
    return [
      'redirectField' => 'legacyUrl',
    ];

Installation

You can install this plugin with Composer.

Open your terminal and run the following commands:

# go to the project directory
cd /path/to/project

# tell composer to use the plugin
composer require miranj/craft-redirector:dev-dev

# tell Craft to install the plugin
./craft plugin/install redirector

Requirements

This plugin requires Craft CMS 3, 4, or 5.

Brought to you by Miranj