1

I am unable to match location with below mentioned pattern, I want to set expires header to 24 hrs. but it is not working. It works if I just use below mentioned regex :

location ~* .*abc\.php.* {
expires 24h;
}

Below example does not work.

location ~* .*abc\.php.*xyz=detail.*login_something=.* {
expires 24h;
}

There is lot of content in between and after of "abc.php" & "xyz=detail" & "login_something=" so I have to use .* only.

Thanks in advance!

4
  • Anything from the ? onwards is the query string and is not considered when matching the URI to a location. Read this for more. Commented Oct 13, 2016 at 7:46
  • @WiktorStribiżew : That does not work. Commented Oct 13, 2016 at 9:57
  • @KeyurM: Sure, read Richard's comment why. Commented Oct 13, 2016 at 9:58
  • @RichardSmith : Thanks for the info! Is there any work around to achieve this ? Commented Oct 13, 2016 at 9:58

1 Answer 1

1

There are multiple ways to achieve what you are trying to do, but the simplest method is to apply your mega regex to a variable that contains the entire URI (including the query string). This would be $request_uri

The second problem is how to manipulate expires and again, rather than use multiple blocks and have to reimplement PHP directives in each one, just use the map directive as detailed in the expires documentation.

For example:

map $request_uri $expires {
    default                                   off;
    ~*abc\.php.*xyz=detail.*login_something=  24h;
}

server {
    ...
    expires $expires;
    ...
}
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.