I have a problem, I'm trying to catch all PHP scripts except one in my NGINX configuration for my HTTP domain configuration:
I have a general rule for all PHP files
location ~ \.php$ {
include fastcgi_params;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-fpm:
fastcgi_pass unix:/var/run/php7.4-fpm.$user.sock;
#fastcgi_pass php7-fpm-sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 600;
}
But I need to handle old PHP script from the old site to redirect to a HTTPS link (with a different structure).
I have tried to put this in PHP handler, in location / {} block, in location /download {} block, but it all fails and the default trigger is pulled on this script (404 in PHP handler)
rewrite ^/download\.php\?file_id=(.*)$ https://$server_name/download/id/$1 permanent;
How to handle it properly? Where to put this exception in NGINX configuration to make it work? What am I doing wrong?
PS. I need to keep a separate HTTP config for other things.