skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    this is what worked for me:

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

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search