netlify / ask-netlify

A place to submit questions for Netlify to answer in tutorials, podcasts and blog posts
https://ask.netlify.com
32 stars 8 forks source link

RegEx support for redirects #28

Closed manniL closed 5 years ago

manniL commented 5 years ago

About me

My question in a little more detail

I really enjoy the redirect system and the idea of splats and placeholders. However, I feel like sometimes it'd be useful to have more freedoms to customize redirects.

Especially I'm missing that we can't use regular expressions to match (and re-insert) URLs or query variables as you can with Apache, Nginx or even other Netlify competitors.

Will there be RegEx support for redirect rules in the future or would you suggest using a custom function instead? 🤔

ericmarcos commented 5 years ago

Is this available already? I couldn't find any documentation.

manniL commented 5 years ago

@ericmarcos I don't think so.

j-f1 commented 5 years ago

It looks like they never finished episode 3 :(

andre-brdoch commented 4 years ago

It would be great if something like this would be possible:

/:dir/*.pdf /:dir/:splat 301!
ddamato commented 4 years ago

I actually have a more involved use-case. It would look something like this

/dir/:pdf /api/tracker?pdf=:pdf
/dir/:pdf.pdf https://bucket.s3.amazonaws.com/dir/:pdf.pdf 200

The API would then redirect to the url with extension with a location header.

So basically, the redirects handle a proxy to the API in order to track the number of times the file was requested. I used to do this with Apache but I think if the tokens were a little more strict here it could work.

To the user, all it would look like is that the url is just adding the extension for the file.

philsturgeon commented 4 years ago

I want to redirect from

/api/2018/04/13/openapi-and-json-schema-divergence-solved

to

/2018/openapi-and-json-schema-divergence-solved

but that doesnt seem possible with the * and splat...

j-f1 commented 4 years ago
/api/:year/:month/:day/:slug    /:year/:slug