0
votes

my old server had this in the htaccess file:

< FilesMatch "^resort$"> ForceType application/x-httpd-php < /FilesMatch>

where I had a resort php file (without the php extension)... so the file was domain.com/resort/param1/param2

I'm struggling to make the equivalent work for nginx...

i've tried these items, but none work:

location = /resort/ {

  • try_files $uri /resort.php;

  • try_files $uri $uri/ @extensionless-php;

  • try_files $uri $uri/ $uri.html $uri.php?$query_string;

  • try_files $uri $uri/ /resort.php$is_args$args;

  • rewrite ^(.*)$ /resort.php last;

    }

So how do I execute the resort file as php, when this url is in the browser: domain.com/resort/param1/param2.php

THANKS!

PS. would love some pages/resources/tutorials that explain "apache to nginx" for people who don't understand nginx :)

i've been to nginx site, but IMO, I need to know more than I do to figure it out or understand what the nginx site is saying.

update: i think this is close, but still not working :(

this is url: domain.com/resort/city/state.php

here is directive:

location ~ /resort/ {
     rewrite ^/resort/(.*)/(.*) /resort/$1/$2 break;
}
2
FYI. I'm on a plesk server and I'm adding this to the "Additional nginx directives" section... so I'm thinking I only need to know/add the correct location part and the correct try_files/rewrite part.user1864734
there error I get: 17938#0: *92491 FastCGI sent in stderr: "Access to the script '/var/www/vhosts/domain.com/httpdocs/resort' has been denied (see security.limit_extensions)" while reading response header from upstream security.limit_extensions = FALSEuser1864734

2 Answers

1
votes

this is what worked for me:

location ^~ /resort/ {
      try_files $uri $uri/ /resort.php; }
0
votes

To execute a file without a .php extension as though it was a PHP file, you will need to replicate the location block that handles those types of request.

It will look something like this:

location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass ...;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

To process the URI /resort/param1/param2 using the PHP file located at /resort, you might use something like:

location ~ ^/resort/ {
    include fastcgi_params;
    fastcgi_pass ...;
    fastcgi_param SCRIPT_FILENAME  $document_root/resort;
}

See this document for location syntax.