2

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

Do I have to configure my PHP file for get it working? Any ideas?

Thanks!

1 Answer 1

3

Try this:

location / {

    rewrite ^/my_dir/filename.php?parameter=(.*)/$ /my_dir/$1/ permanent;
}

Or:

location /my_dir {

    rewrite ^/filename.php?parameter=(.*)/$ /$1/ permanent;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.