URL Rewrite (!= Redirect) #58

Open
opened 2024-01-25 17:34:22 +00:00 by quentin · 0 comments
Owner

Netlify has an URL rewrite mechanism that is often used for SPA applications that have a single index.html + javascript that change its behavior according to the text in the URL bar.

For example, a blog post discussing this issue with React: https://www.codemzy.com/blog/cloudflare-reactjs-spa-routing

Netlify has a dedicated page here documenting its behavior: https://docs.netlify.com/routing/redirects/rewrites-proxies/

When you assign an HTTP status code of 200 to a redirect rule, it becomes a rewrite. This means that the URL in the visitor’s address bar remains the same, while Netlify’s servers fetch the new location behind the scenes.

If we decompose the feature based on 2 examples:

/*  /index.html  200

If the requested URL does not map to an existing file, serve index.html

/*  /index.html  200!

Even if the requested URL maps to an existing file, serve index.html

I think we can implement that on the Amazon API: https://docs.aws.amazon.com/AmazonS3/latest/API/API_RoutingRule.html

The first one would require a Condition with an HttpStatusCode 404.
The second one would not require any Condition.

To implement the rewrite for both cases, we could set the HttpStatusCode of the Redirect to 200:
https://docs.aws.amazon.com/AmazonS3/latest/API/API_Redirect.html

And implement this special behavior where we rewrite instead of redirecting.
It will probably an extension of the Amazon API, and might even break some commands that are checking data before sending them (I suppose they expect 3xx codes only), but on the server side, it should be a backward compatible change.

Netlify has an URL rewrite mechanism that is often used for SPA applications that have a single index.html + javascript that change its behavior according to the text in the URL bar. For example, a blog post discussing this issue with React: https://www.codemzy.com/blog/cloudflare-reactjs-spa-routing Netlify has a dedicated page here documenting its behavior: https://docs.netlify.com/routing/redirects/rewrites-proxies/ > When you assign an HTTP status code of 200 to a redirect rule, it becomes a rewrite. This means that the URL in the visitor’s address bar remains the same, while Netlify’s servers fetch the new location behind the scenes. If we decompose the feature based on 2 examples: ``` /* /index.html 200 ``` If the requested URL does not map to an existing file, serve index.html ``` /* /index.html 200! ``` Even if the requested URL maps to an existing file, serve index.html I think we can implement that on the Amazon API: https://docs.aws.amazon.com/AmazonS3/latest/API/API_RoutingRule.html The first one would require a Condition with an HttpStatusCode 404. The second one would not require any Condition. To implement the rewrite for both cases, we could set the HttpStatusCode of the Redirect to 200: https://docs.aws.amazon.com/AmazonS3/latest/API/API_Redirect.html And implement this special behavior where we rewrite instead of redirecting. It will probably an extension of the Amazon API, and might even break some commands that are checking data before sending them (I suppose they expect 3xx codes only), but on the server side, it should be a backward compatible change.
quentin added the
cat
feature
label 2024-01-25 17:34:22 +00:00
quentin added this to the Deuxfleurs Website project 2024-01-25 17:34:23 +00:00
quentin added the
difficulty
mid
label 2024-01-25 17:34:42 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Deuxfleurs/guichet#58
No description provided.