Answers.Body: <p>You can implement your own redirect.</p>
  <p>Add a route in <code>/admin/settings/routes</code></p>
  <p>Declare it like so:</p>
  <p><a href="https://i.sstatic.net/rQVml.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rQVml.png" alt="route definition" /></a></p>
  <p>Create a new template <code>templates/page/_redirect.twig</code>:</p>
  <pre><code>{% set requestedSlug = craft.app.request.getSegment(4) %}
  
  {% set redirectToEntry = craft.entries()
  .slug(requestedSlug|literal)
  .one() %}
  
  {% redirect redirectToEntry.url %}
  </code></pre>
  <p>That should redirect nicely.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T13:39:54.337Z
Answers.Text: Oh amazing, thank you!
Answers.UserDisplayName: Emma Swann
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T06:25:50.707Z
Answers.LastActivityDate: 2022-12-13T06:25:50.707Z
Answers.UserDisplayName: Capsule
Body: <p>It has been recommended to me to change our URL structure from:</p>
  <p><code>site.com/yyyy/mm/dd/slug</code></p>
  <p>to</p>
  <p><code>site.com/variable-element/slug</code></p>
  <p>where the variable may be two segments.</p>
  <p>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?</p>
  
Tags: <url><redirect><plugin-retour><uri>
Title: Best way to redirect old URLs
ThreadText: # Best way to redirect old URLs
  
  (Asked by: username_0 on 2022-12-12)
  
  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?
  
  **Tags:** url, redirect, plugin-retour, uri
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-12-13. Score: 2
  
  You can implement your own redirect.
  
  Add a route in `/admin/settings/routes`
  
  Declare it like so:
  
  [![route definition](https://i.sstatic.net/rQVml.png)](https://i.sstatic.net/rQVml.png)
  
  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.
  
  > **Comments:**
  > **username_0**: Oh amazing, thank you!  
  
  ---
  
  