1

I have an NGINX background on my server. I cannot figure out why my rules doesn't work.

How can I redirect or rewrite it so I could open URL with the same content, for example:

http://www.example.com/my_dir/value/

If I have this URL, for example:

http://www.example.com/my_dir/filename.php?parameter=value

I tried some solutions but they didn't worked:

Case #1:
location /my_dir/ {
  if ($args ~* "filename.php/?parameter=value1") {
      rewrite ^ http://www.example.com/my_dir/$arg_param1? last;
  }
}

Case #2:
rewrite ^/my_dir/(.*)$ /filename.php?parameter=$1 last;

Case #3:
location /my_dir {
    try_files $uri $uri/ my_dir/filename.php?$args;
}

Case #4:
location /my_dir/ {
    rewrite ^/my_dir/filename.php?parameter=(-+([a-zA-Z0-9_-]+))?\$ /filename.php?parameter=$1 last;
}

Is that possible? Do I have to configure my PHP file for get it working?

Any ideas?

Thanks!

2 Answers 2

2

Visit : domain.com/folder/abc --> domain.com/folder/filenam.php?url=abc

//this is inside the http block
map $request_uri $request_basename {
    ~/(?<captured_request_basename>[^/?]*)(?:\?|$)
$captured_request_basename;
}

server {
    [snip]
    location /folder {
        try_files folder folder/ /folder/filename.php?url=$request_basename;
    }
}
1

Simply use this try_files directive inside your sever block:

try_files my_dir my_dir/ /my_dir/filename.php?$args;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .