1

I have a static site with a setup like:

location / { index index.html; }
location /about/ { index about.html; }
location /app/ { index app.html; }
location /app/support/ { index support.html; }

This approach will not scale but I would like to continue this naming practice for the index files.

How to write a common case to resolve wrapping directory's names into index files with the same names? Thanks!

  • Why not use index.html in all directories? – Alexander Tolkachev Jun 28 '17 at 7:58
  • @AlexanderT It's more convenient for working with them – ten "index.html" tabs in a text editor are slightly confusing. – Ivan Mir Jun 28 '17 at 14:37
1

You could use try_files instead of an index directive. See this document for more. For example:

location ~ ^(.*)/([^/]+)/$ {
    try_files $1/$2/$2.html =404;
}

Placement of regular expression location blocks is critical as they are evaluated in order. See this document for details.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.