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.

  • 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. – Tero Kilkanen Sep 03 '16 at 01:59
  • 1
    Second example couldn't match anything. Either it's a typo or your request is processed within some other location. – Alexey Ten Sep 03 '16 at 08:08

1 Answers1

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;
} 
Jonah Benton
  • 1,242
  • 7
  • 13
  • 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. – Tero Kilkanen Sep 03 '16 at 01:54
  • Sure, just sloppy writing, there are issues using match groups (proxy_pass, etc). Will edit. – Jonah Benton Sep 03 '16 at 02:57