WEBVTT

00:04.490 --> 00:10.850
Following on from the previous list and on redirect and rewrites engine X provides us with a third somewhat

00:10.850 --> 00:17.750
unique directive called Tri files try files as with the return and rewrite directives can be used in

00:17.750 --> 00:19.160
the server context.

00:19.280 --> 00:26.810
So applying to all incoming requests or inside a location context with trifles allows us to do is have

00:26.810 --> 00:33.860
engine X check for a resource to respond worth in any number of locations relative to the root directory

00:34.250 --> 00:38.900
with a final argument that result in a rewrite and re-evaluation.

00:38.900 --> 00:40.900
As with the rewrite directive.

00:41.180 --> 00:44.530
This is a directive which being so unique in its behaviour.

00:44.720 --> 00:50.600
I'd suggest you really try out in a number of ways using a simple test configuration but nonetheless

00:50.630 --> 00:53.360
will cover some arbitrary examples.

00:53.360 --> 00:59.570
First off are clear these rewrites from the previous lesson leave the Greek location as we can reuse

00:59.600 --> 00:59.830
that.

00:59.840 --> 01:06.320
In this lesson and also get rid of Greet slash John then in the server context.

01:06.320 --> 01:15.470
So applying to all incoming requests I'll say try files slash thumb Dot be in G first which we know

01:15.470 --> 01:16.490
exists.

01:16.670 --> 01:18.190
Followed by slash.

01:18.200 --> 01:19.010
Great.

01:19.310 --> 01:25.790
So what this directive is doing then all the time being in the server context is checking whether slash

01:25.820 --> 01:33.290
sites slash demo slash thumbed or PRNG exists and if it does serve it.

01:33.290 --> 01:39.300
If however this first argument doesn't exist move on and try the next one and so on.

01:39.320 --> 01:45.260
In our case some Thumper's PRNG definitely exists relative to the root directory so this should be served

01:45.260 --> 01:47.120
for all requests.

01:47.120 --> 01:50.150
Save this and reload the configuration.

01:50.150 --> 01:56.630
My browser has the demo side loaded at the moment so refresh and sure enough we get thumbed on PRNG.

01:56.900 --> 01:59.490
Try a u r l that doesn't exist at all.

01:59.570 --> 02:01.750
I'll say slash something.

02:02.470 --> 02:03.730
And the same.

02:03.970 --> 02:07.660
Or style C S S which does exist.

02:07.660 --> 02:09.300
No change.

02:09.310 --> 02:16.240
Try files intercept the requests checks if this first argument exists and serves it regardless of the

02:16.240 --> 02:16.690
request.

02:16.690 --> 02:22.580
You are I meaning that should we change some doppie energy to a resource that doesn't exist.

02:22.810 --> 02:30.460
Cat dog B and G drive files won't find it and move on to the next argument slash greet very important

02:30.460 --> 02:31.340
however when.

02:31.340 --> 02:33.920
Try files reaches its last argument.

02:34.000 --> 02:37.800
That argument is treated as an internal rewrite meaning.

02:37.810 --> 02:45.760
In this case and only in this case will the rewritten request also be re-evaluated and caught by this

02:45.820 --> 02:47.890
slash Greek location.

02:48.640 --> 02:53.050
Reload still on Style dotsie says Worth.

02:53.050 --> 02:53.760
Try files.

02:53.770 --> 02:57.360
No longer looking for thumb don't be in G reload.

02:57.550 --> 02:58.890
Hello user.

02:58.890 --> 03:05.830
That response from the Greek location as trifocals rewrote the request to slash greet and the same for

03:05.830 --> 03:06.180
the root.

03:06.190 --> 03:07.040
You are right.

03:08.170 --> 03:09.350
Typically then the.

03:09.360 --> 03:10.080
Try files.

03:10.080 --> 03:17.830
DirecTV is used with engine X variables for example to first check the request as it is we can add as

03:17.830 --> 03:19.450
the first argument here.

03:19.450 --> 03:20.440
The variable.

03:20.440 --> 03:21.400
You are right.

03:21.670 --> 03:23.520
Meaning before anything else.

03:23.530 --> 03:26.830
Try the you are I save and reload.

03:27.830 --> 03:30.300
This time try thumb dot P in G.

03:31.710 --> 03:32.420
And add loads.

03:32.460 --> 03:34.350
As it exists on the desk.

03:34.350 --> 03:36.580
Same for Style dotsie SS.

03:37.990 --> 03:40.070
And indexed old age to you Mel.

03:42.190 --> 03:49.060
Now knowing the last argument rewrites and is exactly that the last option this should ideally be something

03:49.060 --> 03:50.780
that won't ever fail.

03:50.800 --> 03:57.450
For example I'll create a new location to handle not found requests friendly underscore foro for.

03:58.180 --> 04:01.130
Which just returns a four of four worth.

04:01.150 --> 04:01.700
Sorry.

04:01.720 --> 04:03.670
That file could not be found.

04:05.760 --> 04:10.050
And use this location as the final argument on the trifocals directive.

04:10.900 --> 04:12.500
Save and reload.

04:14.210 --> 04:20.250
Make a request for a resource which doesn't exist for example slash nothing which will cause engine

04:20.260 --> 04:24.710
X to first look for the you are right as it is relative to the root.

04:24.950 --> 04:27.720
So slash sites slash demo slash.

04:27.740 --> 04:29.980
Nothing that doesn't exist.

04:29.990 --> 04:33.950
Meaning Go check for Slash sites slash demo slash cat.

04:33.970 --> 04:36.690
Don't be in G also doesn't exist.

04:36.800 --> 04:43.640
Then try slash greet which whilst we have a location for it still doesn't exist relative to the root

04:43.640 --> 04:44.680
directory.

04:44.750 --> 04:48.530
Remember only the very last argument causes a rewrite.

04:48.530 --> 04:54.440
These first ones only have engine X check relative to the root directory which means the slash nothing

04:54.440 --> 05:01.940
will finally be rewritten to slash friendly foro for revaluated and caught by the match and location

05:02.270 --> 05:04.930
resulting in this message and a foro for.

05:05.720 --> 05:06.470
Enter.

05:06.650 --> 05:09.220
And sure enough we get that message.

05:09.350 --> 05:13.660
We can confirm the status code using cool copy that you are real.

05:14.470 --> 05:15.190
Cool.

05:15.220 --> 05:15.840
Capital.

05:15.880 --> 05:16.620
I.

05:16.810 --> 05:19.190
And that request for a 4.

05:19.210 --> 05:20.130
Not Found.

05:20.980 --> 05:21.220
OK good.

05:21.220 --> 05:24.900
Very last thing I want to show in this lesson is named locations.

05:25.060 --> 05:31.030
This being a concept which you might run into at some point and name location simply means assigning

05:31.030 --> 05:35.850
a name to a location context and using a directive such as Try files.

05:35.950 --> 05:42.760
Use that location by its name ensuring no revaluation has to happen on that final argument but instead

05:42.760 --> 05:49.270
just a definite call to the name location to name a location then more specifically this friendly underscore

05:49.270 --> 05:57.790
foro for use an at sign with a name at friendly underscore foro for doing the same on the location in

05:57.790 --> 05:59.080
order to you name it.

05:59.660 --> 06:00.640
Reload.

06:02.400 --> 06:03.850
And the browser.

06:03.930 --> 06:09.500
We get the same back to some DOD PRNG it's found and served.
