A Craft CMS plugin for handling legacy paths and URLs by preventing 404s and redirecting to the new entry's URL.
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.
-
Create a new field of type URL. Set the Allowed URL Types to Web Page.
-
Add this field to all sections where entries have URLs of their own.
-
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', ];
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
This plugin requires Craft CMS 3, 4, or 5.
Brought to you by Miranj