redirect to a .php file with try_files if required .php file not found

ST smntov at
Thu Mar 15 11:32:34 UTC 2018


maybe I pasted too much of my config, basically the important line is:

        try_files $uri /virtual_new.php =404;

Does it look legitim to you? Is it the proper way to redirect in such a
case or should I better use rewrite/redirect?

Thank you!


I would like to redirect to /virtual_new.php with try_files if
required .php file not found, is it the right way to do so:

location ~ \.php$ {

        if ($args ~ "netcat_files/") {
             expires 7d;
             add_header Cache-Control "public";

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $uri /virtual_new.php =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root
        include fastcgi_params;

Thank you!

More information about the nginx mailing list