Reputation: 1055
I'm using this rewrite:
location = /example-page {
try_files $uri /pages/example-page.php;
}
This rewrite is causing $_GET
not to be available for some reason.
When I go to example-page.php?test
and use print_r($_GET);
it returns an empty Array. If however I access the file directly, as in /pages/example-page.php?test
I get Array ( [test] => )
My question is, how can I make it so that all these vars, like $_GET
are kept, using the rewrite?
Upvotes: 0
Views: 89
Reputation: 9855
The corrected rewrite as mentioned in comment, while will work, is the least preferred:
location = /example-page {
try_files $uri /pages/example-page.php$is_args$args;
}
It is sub-optimal, because it checks existence of file <webroot>/example-page
for every request to /example-page
URI. Sure enough, this file does not exist to begin with. So all the file existence checks are in vain. That, depending on traffic and disk used, will be a reason for performance issues.
Getting rid of try_files
to reduce stat
system calls is preferable in this case. Simply tell NGINX to route request via PHP-FPM, as well as which filename the PHP-FPM has to use for processing:
location = /example-page {
fastcgi_param SCRIPT_FILENAME $document_root/pages/example-page.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/example.com.sock;
}
Upvotes: 1