user1864734
user1864734

Reputation: 135

filesmatch htaccess convert to nginx (on plesk)

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/ {

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;
}

Upvotes: 0

Views: 1581

Answers (2)

user1864734
user1864734

Reputation: 135

this is what worked for me:

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

Upvotes: 1

Richard Smith
Richard Smith

Reputation: 49762

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.

Upvotes: 0

Related Questions