1

I have 2 subfolders, they are opened on my_url/test1 and my_url/test2

location /test1 {
    index index.html index.php; ## Allow a static html file to be shown first
    try_files $uri $uri/ /test1 /index.php;
    expires 30d; ## Assume all files are cachable
}

location /test2 {
    index index.html index.php; ## Allow a static html file to be shown first
    try_files $uri $uri/ /test2/index.php;
    expires 30d; ## Assume all files are cachable
}

I want to add 3 additional test subfolders (test3, test4, test5) I can continue writing:

location /test3 {
    index index.html index.php; ## Allow a static html file to be shown first
    try_files $uri $uri/ /test3/index.php;
    expires 30d; ## Assume all files are cachable
}

etc. But May be there is some standart way not to dublicate config? Like

location /(subfolder) {
    index index.html index.php; ## Allow a static html file to be shown first
    try_files $uri $uri/ /(subfolder)/index.php;
    expires 30d; ## Assume all files are cachable
}
freento
  • 135
  • 1
  • 3
  • 12

1 Answers1

1

You almost got it on your last location statement, just replace /(subfolder) to /, and the subfolder string on the line with try_files to /$uri/index.php instead of /(subfolder)/index.php:

location / {
  index index.html index.php;
  try_files $uri $uri/ /$uri/index.php;
  expires 30d;
}
Marcel
  • 1,730
  • 10
  • 15