aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
448 stars 113 forks source link

How to properly redirect using regex #816

Open akefirad opened 4 years ago

akefirad commented 4 years ago

Please describe which feature you have a question about? I'm trying to redirect /<3-digit-integer> to /code/<same-integer> but for some reason I can't get it working. What I tried so far (I wasn't sure about the exact syntax):

/<[0-9]{3}> to /code/<*>
/</[0-9]{3}/> to /code/<*>
/<^[0-9]{3}$> to /code/<*>
/</^[0-9]{3}$/> to /code/<*>

Can someone please take a look and tell me if I'm missing anything here. Thanks.

nimacks commented 4 years ago

Please refer to our documentation which provides examples on redirects. https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html

Let us know if that doesn't work for you.

akefirad commented 4 years ago

No, not really. I already talked to AWS support and showed the whole thing. For some reason the exact regex above doesn't work.

WolfyUK commented 3 years ago

@akefirad Did you ever get a resolution to this? It seems to me like regular expressions just do not work as advertised in the documentation.

akefirad commented 3 years ago

Nope. Seems messed up 😞

ganipcanot commented 2 years ago

Resolving due to age - please re-open if you are still experiencing issues.

akefirad commented 2 years ago

Resolving due to age

Not sure if "age" can resolve such issues. Perhaps "Closing due to age" is a better wording.

please re-open if you are still experiencing issues.

Not sure why we should retry. There's no update regarding any fix. If nothing is fixed then people would still be experiencing the issue.

simonjpartridge commented 2 years ago

I'm experiencing this exact same problem

iceye commented 2 years ago

It's impossible to have regex working. For example, I want a 404 rewrite to index for ANY 404 path ending with "download/": /</^.+\/download\/?$/> -> index.html (404-200 rewrite)

Why this is not working (never match). If I use an exact URL it works perfectly. Are there any limitations on the number of 404 rewrites?

kookster commented 2 years ago

I'm seeing the same - regular expressions don't seem to work at all.

amatzen commented 2 years ago

December 2021: I'm having the issue as well.

taylormadeapps commented 2 years ago

I think you need to escape the / characters like so \/ Can't get capture groups working though. Desperately needed - as per https://github.com/aws-amplify/amplify-hosting/issues/570

tatethurston commented 1 year ago

Please refer to our documentation which provides examples on redirects. https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html

Let us know if that doesn't work for you.

The only reference to regex is https://docs.aws.amazon.com/amplify/latest/userguide/redirects.html#redirects-for-single-page-web-apps-spa which does not demonstrate capture groups. The docs also do not specifically mention regex anywhere. There is a large opportunity to better document regex usage.

jackdewhurst commented 1 year ago

Agreed the documentation on regex in redirects is basically nonexistent. Can't get anything to work

dannyhchan commented 1 year ago

Agree, they need better documentation for this.

Janosch commented 3 weeks ago

I don't know if a capture group is possible, but I was able to make something work which is close enough for my purpose:

Source: </^\/(?!frontend\/).*$/><*> Target:/frontend/<*>

So it is possible to combine the capture-like thing <*> with a regex. Please note that you have to escape forward slashes as shown in my example. This is probably why it did not work for @akefirad and @iceye. Apparently, regexes need to be placed inside of </ and />.

It is sad that AWS is unable to resolve this and provide proper docs. This issue has been reported almost four years ago!