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.
I too was hoping to leverage a regex in _redirects for the same exact purpose (rewriting underscores in blog post links to hyphens); sadly, my pre-Web file naming convention has not withstood the test of time.
Surprisingly, however, the Google developer documentation style guide has a rather nuanced view on underscores in filenames:
Make file and directory names lowercase. In general, separate words with hyphens, not underscores. Use only standard ASCII alphanumeric characters in file and directory names.
Exceptions for consistency
If you’re adding to a directory where everything else already uses underscores, and it’s not feasible to change everything to hyphens, it’s okay to use underscores to stay consistent.
Recommended: avoiding-cliches.jd
Sometimes OK: avoiding_cliches.jd
Would still be awesome if _redirects could support regexes, but underscores do not appear to be a total disaster from Google’s point of view.
i had a chance to confirm today that we don’t, at this time, support regex in redirects. I can file a feature request on this, but i can’t say when we might work on this unfortunately
sadly i see no movement on the issue. I’ve commented that we are still getting asks for this, and also looped in the product team and provided the feedback i saw surfaced in this thread. hopefully someday. if others are follow along, please comment on this feature request and let us know how having regex would improve our products for you - the more compelling use cases we have, the more likely we are to make this happen.
Has there been any movement on this feature request? We’re moving a bunch of sites to Netlify and are really going to miss this functionality if it’s not available.