I am achieving the wished result with the following configuration snippet:
location = / { index index.php; } location / { try_files $uri /index.php?tags=$request_uri; }
try_files
tries... files. When you seek /
with it, you search for a file with the same name, it is not interpreted as 'find the index file'. index
does that job. Hence you need to separate this special case from the default, fall-back location.
The best part is your last wish: the arguments won't even be encoded since they do not need to (only the first question mark of a URI is relevant as everything following is an argument anyway).
Mind the use of $request_uri
(which contains the requested URI, with arguments, but does not normalize/cleanse it) instead of the normalized $uri
(which cleans up the URI and remove arguments). Thus you may end up with:
///foo?bar=yes => index.php?tags=///foo?bar=yes
If you mind about it, you may use $uri
in combination with $args
:
location = / { index index.php; } location / { try_files $uri /index.php?tags=$uri?$args; }
producing:
///foo?bar=yes => index.php?tags=/foo?bar=yes