Is it possible to use regular expressions when setting up redirects?
I have a bunch of URLs that originally had underscores in them, but now have dashes instead (something something SEO). Unfortunately, they are still linked to from around the net using the underscore URLs and I would like to redirect them to their proper dasherized versions instead of serving 404 pages.
- https://mentalized.net/journal/2006/10/24/browser_size_does_matter_actual_numbers/ should really be at https://mentalized.net/journal/2006/10/24/browser-size-does-matter-actual-numbers/
- https://mentalized.net/activity_indicators/ should be at https://mentalized.net/activity-indicators/
There are a large number of other URLs following the same pattern and I am far too lazy to generate a line with a redirect for each.
In the olden days of Apache I had a
RewriteRule ^(journal/.*?/[^/]*?)_(.*_.*)$ /$1-$2 [N] RewriteRule ^(journal/.*?/[^/]*?)_(.*)$ /$1-$2 [R=301]
which did the trick. Something similar in
_redirects would be perfectly fine for me, but it doesn’t seem like it’s supported.
What are my options? Could it be handled by an Edge Handler if I were to write one?