Following on from the previous list and on redirect and rewrites engine X provides us with a third somewhat
unique directive called Tri files try files as with the return and rewrite directives can be used in
the server context.
So applying to all incoming requests or inside a location context with trifles allows us to do is have
engine X check for a resource to respond worth in any number of locations relative to the root directory
with a final argument that result in a rewrite and re-evaluation.
As with the rewrite directive.
This is a directive which being so unique in its behaviour.
I'd suggest you really try out in a number of ways using a simple test configuration but nonetheless
will cover some arbitrary examples.
First off are clear these rewrites from the previous lesson leave the Greek location as we can reuse
that.
In this lesson and also get rid of Greet slash John then in the server context.
So applying to all incoming requests I'll say try files slash thumb Dot be in G first which we know
exists.
Followed by slash.
Great.
So what this directive is doing then all the time being in the server context is checking whether slash
sites slash demo slash thumbed or PRNG exists and if it does serve it.
If however this first argument doesn't exist move on and try the next one and so on.
In our case some Thumper's PRNG definitely exists relative to the root directory so this should be served
for all requests.
Save this and reload the configuration.
My browser has the demo side loaded at the moment so refresh and sure enough we get thumbed on PRNG.
Try a u r l that doesn't exist at all.
I'll say slash something.
And the same.
Or style C S S which does exist.
No change.
Try files intercept the requests checks if this first argument exists and serves it regardless of the
request.
You are I meaning that should we change some doppie energy to a resource that doesn't exist.
Cat dog B and G drive files won't find it and move on to the next argument slash greet very important
however when.
Try files reaches its last argument.
That argument is treated as an internal rewrite meaning.
In this case and only in this case will the rewritten request also be re-evaluated and caught by this
slash Greek location.
Reload still on Style dotsie says Worth.
Try files.
No longer looking for thumb don't be in G reload.
Hello user.
That response from the Greek location as trifocals rewrote the request to slash greet and the same for
the root.
You are right.
Typically then the.
Try files.
DirecTV is used with engine X variables for example to first check the request as it is we can add as
the first argument here.
The variable.
You are right.
Meaning before anything else.
Try the you are I save and reload.
This time try thumb dot P in G.
And add loads.
As it exists on the desk.
Same for Style dotsie SS.
And indexed old age to you Mel.
Now knowing the last argument rewrites and is exactly that the last option this should ideally be something
that won't ever fail.
For example I'll create a new location to handle not found requests friendly underscore foro for.
Which just returns a four of four worth.
Sorry.
That file could not be found.
And use this location as the final argument on the trifocals directive.
Save and reload.
Make a request for a resource which doesn't exist for example slash nothing which will cause engine
X to first look for the you are right as it is relative to the root.
So slash sites slash demo slash.
Nothing that doesn't exist.
Meaning Go check for Slash sites slash demo slash cat.
Don't be in G also doesn't exist.
Then try slash greet which whilst we have a location for it still doesn't exist relative to the root
directory.
Remember only the very last argument causes a rewrite.
These first ones only have engine X check relative to the root directory which means the slash nothing
will finally be rewritten to slash friendly foro for revaluated and caught by the match and location
resulting in this message and a foro for.
Enter.
And sure enough we get that message.
We can confirm the status code using cool copy that you are real.
Cool.
Capital.
I.
And that request for a 4.
Not Found.
OK good.
Very last thing I want to show in this lesson is named locations.
This being a concept which you might run into at some point and name location simply means assigning
a name to a location context and using a directive such as Try files.
Use that location by its name ensuring no revaluation has to happen on that final argument but instead
just a definite call to the name location to name a location then more specifically this friendly underscore
foro for use an at sign with a name at friendly underscore foro for doing the same on the location in
order to you name it.
Reload.
And the browser.
We get the same back to some DOD PRNG it's found and served.