Redirects with some pattern matching?

We have to reroute from an old site to a new one, currently I’ve just done some simple redirects, but I was wondering if we could actually route some of the old URLs to the new ones in a smarter fashion. I could probably reroute the 20 or so filters manually but not the 80 or so book URLs.

I’m not even sure this would be possible, but any suggestion greatly appreciated.

We have two types of URL we’d need to redirect:

1. Book Examples
For these we need to loose the ‘/number/’ and the ‘ebook’ from the beginning of the last URL section and convert underscores to dashes

Old URL
/ebooks/4/ebook_dissipation_and_despair/

redirect to:
/books/dissipation-and-despair

another example:

Old URL
/ebooks/8/ebook_lust_over_pendle/

redirect to:
/books/lust-over-pendle


2. Category Examples
For these we need to loose the ‘bycategory/number/number/’, lower case the last URL section and convert any dashes to ‘+’

Old URL
/ebooks/bycategory/3/223/Harry-Potter/

redirect to:
/books/filter:harry+potter

another example:

Old URL
/ebooks/bycategory/10/223/Nicholas-Montserrat/

redirect to:
/books/filter:nicholas+montserrat

As I say, any help much appreciated, it is a non-profit.

No, sadly, it’s not possible with Netlify redirects. However you can use client side redirects, that is, use JavaScript to check the page’s URL, extract the separate parts, convert it to the necessary string and then redirect to that string. The downside is, there must exist an index.html for all these old URLs for this method to work.

Thanks for the info hrishikesh, I had a feeling that would be the case, I shall explore other avenues as you suggest.

1 Like