I'm struggling with nginx config. I have a server block where I want all requests to go to index.php?tags=$uri, unless $uri exists (like index.php?a=b or /?a=b).
I would expect:
try_files $uri index.php?tags=$uri;
but, no, that would be too simple. That doesn't work for /?a=b, which is apparently not found, so it directs to index.php?tags=/
Maybe if I explicitly include an index, which is reasonable:
index index.php;
Nope. No dice. Same exact result across the board.
Also nothing with $args, $request_uri or combinations. Also not it:
try_files $request_uri/index.php $request_uri index.php?tags=$request_uri; // now I'm just guessing
Apache somehow knew what I meant always. Why doesn't nginx? I'd like these redirects (without redirect or if):
/ => /index.php
/index.php => /index.php
/index.php?a=b => /index.php?a=b
/?a=b => /index.php?a=b
/foo => /index.php?tags=foo (or /index.php?tags=/foo)
/foo/bar => /index.php?tags=foo/bar (or /index.php?tags=/foo/bar)
/foo?bar=yes => /index.php?tags=/foo%3Fbar%3Dyes
I'd like the query string to be encoded when redirected, but not the path, but really that's not so important.
(I also don't understand the practical difference between $uri and $request_uri. They seem to be doing the same half the time. But that's for another day.)
Much thanks.