1

How to match for location in Nginx:

  • contains /render/framed/

  • ends with .php

I tried location ~ /render/framed/ { just for contains "/render/framed/" and it works. But couldn't find how to specify, must end with .php

Tried: location ~ /render/framed/+\.php$ {

Is it possible?

4
  • Try /render/framed/.*\.php instead of /render/framed/+\.php$ Commented May 6, 2018 at 19:45
  • @Sergio Unfortunately not working location ~ /render/framed/.*\.php { Commented May 6, 2018 at 19:54
  • 1
    Actually, location ~ /render/framed/.*\.php$ { should work (mind the $ anchor). Probably, you may need to use double quotes, location ~ "/render/framed/.*\.php$" {, not sure though. Also, try replacing ~ with ~* for case insensitive matching. Commented May 6, 2018 at 20:02
  • Yes, should be working but it's not because it's a 404 response error_page 404 = /url_rewriting.php; and location does not work for 404 response. Commented May 6, 2018 at 20:09

1 Answer 1

2

A quick search tells me that NGINX uses the good old PCRE regexp flavor. So is this what you want -

Sometext /render/framed/ .php - Should match

Sometext /render/framed/ .txt - Should not match

Then the below pattern should work. If it does not, can you give some test strings and the desired output.

.*(?:\/render\/framed).*(?:.php)$ 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.