Score:0

How can i use NGINX try_files without changing the browser location for the client?

tn flag

I am using nginx try_files for Server-Side-Rendering. Since GET-parameters affect the resulting html, i want to use try_files to check if i have a prerendered version with the matching query string (file is saved at /posts/?page=5/index.html)

I have the following try_files statement in place:

try_files $uri/$is_args$args/ $uri $uri/ @ssr;

This works, but the client gets redirected to www.page.com/posts/?page=5 which is including the slash of the subdirectory i have. This results in the browser getting a 404 in the end, because that post does not exist.

How can i use try_files like i did, but without actually redirecting the client? To be clear: I want to serve files from whereever with try_files, but not actually let the client know which file is served, thats none of the browsers business in my case.

Is there a way to achieve this?

Richard Smith avatar
jp flag
Try: `try_files $uri/$is_args$args/index.html $uri $uri/ @ssr;`
Jeremias Nater avatar
tn flag
This helped. Where can i find any documentation on this behavior?
sv flag
Not everything is documented. You may check a few things at https://nginx.org/r/try_files
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.