Redirect root collection page to latest sub-collection page

Hi folks. Can get my way around Webflow, but am not an expert. My question is this:

What I would like to have happen is if someone visits domain.com/summit, it will redirect to the latest year. So, if the years are 2021, 2022, 2023, it will redirect to summit/2023.

Ideally, this is a 302 redirect. It’s not permanent and will change every time a new year is added.

Really having a hard time figuring out how to 1) do a 302 redirect, and 2) how to do any kind of redirect dynamically.

I’m fine writing custom scripts if necessary. Appreciate any help!
Al

I believe window.location.replace does a 302.
I’d try-

  • Drop a collection list at the top of your /summit page layout
  • Bind it to your Summit collection
  • Sort descending on year
  • Limit to 1 item starting at 1
  • In that Collection list,drop an HTML Embed with;
<script>
window.location.replace("/summit/{{ slug }}");
</script>

Make sure {{ slug }} is the actual embed field you have the year in.

Publish and try it out.

Notes;

  • replace overwrites history, so Back won’t go back to the redirect page ( which is good ).
  • This is design to go to the latest year in the CMS, not the current year. Use the current year instead in your JS if you want that.
  • You’ll see a flicker as the page begins /summit loading. To minimize that, you can remove all other content, and make the background solid white or black to match the rest of your site. If for some reason it’s slow, you could add a loading lottie.

Hey @memetican - thanks for this reply and sorry for the delay. Been on travel and missed it.

So this isn’t really a 301 nor a 302, which I think is fine, and a pretty creative way to handle it. Do you know how search engines perceive this kind of redirect?

I don’t use this kind of technique for anything I want to SEO, only for UX navigation convenience, such as in your case here.

Your actual year-slugged pages will get the SEO merit.
I doubt /summit would be indexed at all, which is good as it changes anyway.

1 Like