This is related to an old question I asked on SO years ago, for which I never got a proper answer. I'm just setting up a new server (Ubuntu 16.04, Nginx 1.10, PHP 7) and coming back to this.
I have a Question2Answer instance running in a sub folder, with other PHP code running from the root. For the root stuff, I have this in my server block:
location / {
try_files $uri $uri/ /index.php?$request_uri;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
For Q2A, what I had on my old server was:
location /qa/ {
if (!-e $request_filename) {
rewrite ^/qa/(.*)$ /qa/index.php?qa-rewrite=$1 last;
}
}
This does work, but I don't think it's how it should be done (if is evil, etc). I'm sure it must be possible using only try_files
. I've tried this:
location /qa/ {
try_files $uri $uri/ /qa/index.php?qa-rewrite=$uri&$args;
}
But it doesn't work because /qa/
is passed in qa-rewrite
. It should just pass everything after that in the path. Is there some way to remove /qa/
from the $uri
variable?
I've also tried this:
location ~ ^/qa/(.*) {
try_files $uri $uri/ /qa/index.php?qa-rewrite=$1;
}
But this instead starts a download of the PHP code for index.php
! How do I get it to pass that on to the PHP engine?