@frameless/strapi-plugin-old-slugs
v2.0.0
Published
This is a customField to store old slugs for content types
Readme
Strapi Plugin: strapi-plugin-old-slugs
⚠️ This plugin is compatible with Strapi v5 only.
A Strapi plugin that keeps track of previous slugs when they change in the CMS. It stores them in a JSON field called oldSlugs within the content type.
✨ Features
- Automatically saves previous slugs when a slug field is updated.
- Helps maintain URL history for redirects or SEO purposes.
- Configurable to work with specific content types.
🚀 Installation
You can install the plugin using pnpm or npm:
# Using pnpm
pnpm add @frameless/strapi-plugin-old-slugs
# Using npm
npm install @frameless/strapi-plugin-old-slugs
🔧 Configuration
Add the
oldSlugsFieldTo store the previous slugs, you need to add a field of type JSON with the name oldSlugs in the content types where you want to track slug changes.
Option 1: Using Strapi Content-Type Builder You can add the oldSlugs field using the Strapi Content-Type Builder in the Strapi Admin panel:
Open your Strapi Dashboard.
Navigate to Content-Type Builder.
Select the content type you want to modify (e.g., Product).
Add a new field with the following settings:
Field Name: oldSlugs
Type: JSON
Save the changes and restart the server.
For more details, refer to the Strapi Content-Type Builder documentation.
Option 2: Editing the Model File Manually If you prefer, you can manually modify the model file.
Path:
src/api/product/content-types/product/schema.json{ "kind": "collectionType", "collectionName": "products", "info": { "singularName": "product", "pluralName": "products", "displayName": "Product" }, "options": { "draftAndPublish": true }, "attributes": { "title": { "type": "string", "required": true }, "slug": { "type": "string", "required": true, "unique": true }, "oldSlugs": { "type": "json", "default": [] } } }Enable and Configure the Plugin
After installing the plugin, enable and configure it in your Strapi dashboard.
- Navigate to the configuration file:
/config/plugins.ts(or/config/plugins.jsif using JavaScript). - Add the following configuration:
export default ({ env }) => ({ "old-slugs": { enabled: true, config: { contentTypes: [ { uid: "api::product.product", }, ], }, }, });- Navigate to the configuration file:
Configuration Options
| Option | Type | Description |
| -------------- | ----- | ----------------------------------------------------------- |
| contentTypes | Array | List of content types where slug history should be tracked. |
📌 Usage
Once enabled, the plugin will automatically store previous slugs in the oldSlugs JSON field of the specified content types whenever the slug changes.
Example of a product entry with old slugs:
{
"id": 1,
"title": "New Product Name",
"slug": "new-product-name",
"oldSlugs": ["old-product-name", "very-old-product-name"]
}🛠️ Build the Strapi Dashboard
After configuring the plugin and updating the content type, you need to rebuild the Strapi dashboard for the changes to take effect.
Run the following command:
pnpm build && pnpm develop
Or if you're using npm:
npm run build && npm run develop💡 Why Use This Plugin?
- Ensures old slugs are not lost when URLs change.
- Useful for setting up redirects or tracking changes.
- Helps maintain SEO rankings by preserving URL history.
🔥 Contributing
Feel free to submit issues or pull requests to improve this plugin!
📜 License
This plugin is licensed under the EUPL License.
