0

I'm trying to setup location directive to match my request but can't get it working.

Below is my sample request:

/APP/public/api/v1/item/100/type

location ~* ^/APP/public/api/v1/item/(.*)/type { try_files /APP/data/type/$1.json @apache; } 

If I set like below it works:

location = ^/APP/public/api/v1/item/100/type { try_files /APP/data/type/100.json @apache; } 

Am I missing anything ? Thanks.

2
  • I am not sure if this causes your issue, but your regular expression isn't optimal. location ~* ^/APP/public/api/v1/item/([0-9]+)/type$ { allows only numbers one or more times and makes sure there can't be anything extra after the "type" suffix. Commented Sep 3, 2016 at 1:59
  • 1
    Second example couldn't match anything. Either it's a typo or your request is processed within some other location. Commented Sep 3, 2016 at 8:08

1 Answer 1

0

Try just setting up the context for request processing, and then use a rewrite rule inside of that context, something like:

location ~ ^/APP/public/api/v1/item/ { rewrite ^/APP/public/api/v1/item/([0-9]+)/type /APP/data/type/$1.json break; try_files $uri @apache; } 
2
  • What is your source for the "doesn't create match groups" statement? I've used regular expression match groups in location directives succesfully in many occasions. Commented Sep 3, 2016 at 1:54
  • Sure, just sloppy writing, there are issues using match groups (proxy_pass, etc). Will edit. Commented Sep 3, 2016 at 2:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.