1

It has been recommended to me to change our URL structure from:

site.com/yyyy/mm/dd/slug

to

site.com/variable-element/slug

where the variable may be two segments.

Is this something Retour can do, or is there a tag that would recognise segment four as a slug and 'find' the correct new URL?

1 Answer 1

2

You can implement your own redirect.

Add a route in /admin/settings/routes

Declare it like so:

route definition

Create a new template templates/page/_redirect.twig:

{% set requestedSlug = craft.app.request.getSegment(4) %}

{% set redirectToEntry = craft.entries()
.slug(requestedSlug|literal)
.one() %}

{% redirect redirectToEntry.url %}

That should redirect nicely.

1
  • 1
    Oh amazing, thank you!
    – Emma Swann
    Commented Dec 13, 2022 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.