Welcome! Log In Create A New Profile

Advanced

rewrite rule with consistent document structure

xrd
January 16, 2020 11:47AM
I have a directory containing several directories with the exact same structure. I'll be adding more and more directories with the exact same structure. I want to make an NGINX rewrite rule that makes the URL as simple as possible.

For example, here is two of those directories. Notice each has a directory called "public" and then has a bunch of files and other directories.

* directoryA (dir)
*** public (dir)
***** index.html (file)
***** images (dir)
******* image.png (file)
******* image.jpg (file)
* directoryB (dir)
*** public (dir)
***** index.html (file)
***** readme.html (file)
******* a (dir)
********* b (dir)
*********** c (dir)
************* somefile.html
************* nested.jpg

I want to make it so that NGINX serves up the HTML and images from the parent directory and omits the public directory from the URI.

More explicitly, if the server is https://example.com I would like someone to be able to get https://example/directoryB/readme.html. And, if readme.html has an <img src="a/b/c/nested.jpg"> tag inside it, that that gets loaded correctly as well.

I've been trying various combinations of rewrite plus try_files but I'm getting confused by the last, break, etc. And, I think a key distinction is that I don't want to "rewrite" the URI. If I understand things correctly, I don't want to have http://example.com/directoryB/public/index.html to rewrite to https://example.com/directoryB/index.html (I would prefer not to have the public directory available as a possible URI, but I suppose it wouldn't hurt).

I'm struggling with this because I don't know how to "test" my rules without tweaking the configuration, then restarting, tailing the log files, etc. It's been very slow and I would love a better way, so if someone has a suggestion on how , I'm happy to hear it.
Subject Author Posted

rewrite rule with consistent document structure

xrd January 16, 2020 11:47AM

Re: rewrite rule with consistent document structure

J.R. January 16, 2020 01:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 60
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready