Barry Hughes WordPress Developer

WordPress, Nginx and missing get/query data

1 November 2017

Hit a curious problem lately where PHP was unable to “see” the query args being passed in via the URL … in other words, the $_GET superglobal was mysteriously empty when it should not have been.

In this specific scenario, I was looking at a view generated by a plugin which was designed to return a list of posts. Various query args could be applied to this view in order to filter the list, but in my case – in the context of my local dev environment – it stubbornly refused to do so. The URL looked a lot like this example:

(That arguably unnecessary trailing slash at the end of the path, by the way, is a result of WordPress and its canonical redirect behaviour.)

Turned out that in relation to my Nginx config I’d been doing it wrong. The solution – posting here as a note for myself in future and also in case it helps any others with a LEMP setup – lay in the location block within the site’s Nginx config file. Where I had this:

location / {
	try_files $uri $uri/ /index.php?$args;

What I really needed was this:

location / {
	try_files $uri $uri/ /index.php$is_args$args;

A subtle but important difference that got my local environment back on track.

🖇 WordPress Dev | Lemp | Nginx | PHP | WordPress