1 00:00:04,490 --> 00:00:10,850 Following on from the previous list and on redirect and rewrites engine X provides us with a third somewhat 2 00:00:10,850 --> 00:00:17,750 unique directive called Tri files try files as with the return and rewrite directives can be used in 3 00:00:17,750 --> 00:00:19,160 the server context. 4 00:00:19,280 --> 00:00:26,810 So applying to all incoming requests or inside a location context with trifles allows us to do is have 5 00:00:26,810 --> 00:00:33,860 engine X check for a resource to respond worth in any number of locations relative to the root directory 6 00:00:34,250 --> 00:00:38,900 with a final argument that result in a rewrite and re-evaluation. 7 00:00:38,900 --> 00:00:40,900 As with the rewrite directive. 8 00:00:41,180 --> 00:00:44,530 This is a directive which being so unique in its behaviour. 9 00:00:44,720 --> 00:00:50,600 I'd suggest you really try out in a number of ways using a simple test configuration but nonetheless 10 00:00:50,630 --> 00:00:53,360 will cover some arbitrary examples. 11 00:00:53,360 --> 00:00:59,570 First off are clear these rewrites from the previous lesson leave the Greek location as we can reuse 12 00:00:59,600 --> 00:00:59,830 that. 13 00:00:59,840 --> 00:01:06,320 In this lesson and also get rid of Greet slash John then in the server context. 14 00:01:06,320 --> 00:01:15,470 So applying to all incoming requests I'll say try files slash thumb Dot be in G first which we know 15 00:01:15,470 --> 00:01:16,490 exists. 16 00:01:16,670 --> 00:01:18,190 Followed by slash. 17 00:01:18,200 --> 00:01:19,010 Great. 18 00:01:19,310 --> 00:01:25,790 So what this directive is doing then all the time being in the server context is checking whether slash 19 00:01:25,820 --> 00:01:33,290 sites slash demo slash thumbed or PRNG exists and if it does serve it. 20 00:01:33,290 --> 00:01:39,300 If however this first argument doesn't exist move on and try the next one and so on. 21 00:01:39,320 --> 00:01:45,260 In our case some Thumper's PRNG definitely exists relative to the root directory so this should be served 22 00:01:45,260 --> 00:01:47,120 for all requests. 23 00:01:47,120 --> 00:01:50,150 Save this and reload the configuration. 24 00:01:50,150 --> 00:01:56,630 My browser has the demo side loaded at the moment so refresh and sure enough we get thumbed on PRNG. 25 00:01:56,900 --> 00:01:59,490 Try a u r l that doesn't exist at all. 26 00:01:59,570 --> 00:02:01,750 I'll say slash something. 27 00:02:02,470 --> 00:02:03,730 And the same. 28 00:02:03,970 --> 00:02:07,660 Or style C S S which does exist. 29 00:02:07,660 --> 00:02:09,300 No change. 30 00:02:09,310 --> 00:02:16,240 Try files intercept the requests checks if this first argument exists and serves it regardless of the 31 00:02:16,240 --> 00:02:16,690 request. 32 00:02:16,690 --> 00:02:22,580 You are I meaning that should we change some doppie energy to a resource that doesn't exist. 33 00:02:22,810 --> 00: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 34 00:02:30,460 --> 00:02:31,340 however when. 35 00:02:31,340 --> 00:02:33,920 Try files reaches its last argument. 36 00:02:34,000 --> 00:02:37,800 That argument is treated as an internal rewrite meaning. 37 00:02:37,810 --> 00:02:45,760 In this case and only in this case will the rewritten request also be re-evaluated and caught by this 38 00:02:45,820 --> 00:02:47,890 slash Greek location. 39 00:02:48,640 --> 00:02:53,050 Reload still on Style dotsie says Worth. 40 00:02:53,050 --> 00:02:53,760 Try files. 41 00:02:53,770 --> 00:02:57,360 No longer looking for thumb don't be in G reload. 42 00:02:57,550 --> 00:02:58,890 Hello user. 43 00:02:58,890 --> 00:03:05,830 That response from the Greek location as trifocals rewrote the request to slash greet and the same for 44 00:03:05,830 --> 00:03:06,180 the root. 45 00:03:06,190 --> 00:03:07,040 You are right. 46 00:03:08,170 --> 00:03:09,350 Typically then the. 47 00:03:09,360 --> 00:03:10,080 Try files. 48 00:03:10,080 --> 00:03:17,830 DirecTV is used with engine X variables for example to first check the request as it is we can add as 49 00:03:17,830 --> 00:03:19,450 the first argument here. 50 00:03:19,450 --> 00:03:20,440 The variable. 51 00:03:20,440 --> 00:03:21,400 You are right. 52 00:03:21,670 --> 00:03:23,520 Meaning before anything else. 53 00:03:23,530 --> 00:03:26,830 Try the you are I save and reload. 54 00:03:27,830 --> 00:03:30,300 This time try thumb dot P in G. 55 00:03:31,710 --> 00:03:32,420 And add loads. 56 00:03:32,460 --> 00:03:34,350 As it exists on the desk. 57 00:03:34,350 --> 00:03:36,580 Same for Style dotsie SS. 58 00:03:37,990 --> 00:03:40,070 And indexed old age to you Mel. 59 00:03:42,190 --> 00:03:49,060 Now knowing the last argument rewrites and is exactly that the last option this should ideally be something 60 00:03:49,060 --> 00:03:50,780 that won't ever fail. 61 00:03:50,800 --> 00:03:57,450 For example I'll create a new location to handle not found requests friendly underscore foro for. 62 00:03:58,180 --> 00:04:01,130 Which just returns a four of four worth. 63 00:04:01,150 --> 00:04:01,700 Sorry. 64 00:04:01,720 --> 00:04:03,670 That file could not be found. 65 00:04:05,760 --> 00:04:10,050 And use this location as the final argument on the trifocals directive. 66 00:04:10,900 --> 00:04:12,500 Save and reload. 67 00:04:14,210 --> 00:04:20,250 Make a request for a resource which doesn't exist for example slash nothing which will cause engine 68 00:04:20,260 --> 00:04:24,710 X to first look for the you are right as it is relative to the root. 69 00:04:24,950 --> 00:04:27,720 So slash sites slash demo slash. 70 00:04:27,740 --> 00:04:29,980 Nothing that doesn't exist. 71 00:04:29,990 --> 00:04:33,950 Meaning Go check for Slash sites slash demo slash cat. 72 00:04:33,970 --> 00:04:36,690 Don't be in G also doesn't exist. 73 00:04:36,800 --> 00:04:43,640 Then try slash greet which whilst we have a location for it still doesn't exist relative to the root 74 00:04:43,640 --> 00:04:44,680 directory. 75 00:04:44,750 --> 00:04:48,530 Remember only the very last argument causes a rewrite. 76 00:04:48,530 --> 00:04:54,440 These first ones only have engine X check relative to the root directory which means the slash nothing 77 00:04:54,440 --> 00:05:01,940 will finally be rewritten to slash friendly foro for revaluated and caught by the match and location 78 00:05:02,270 --> 00:05:04,930 resulting in this message and a foro for. 79 00:05:05,720 --> 00:05:06,470 Enter. 80 00:05:06,650 --> 00:05:09,220 And sure enough we get that message. 81 00:05:09,350 --> 00:05:13,660 We can confirm the status code using cool copy that you are real. 82 00:05:14,470 --> 00:05:15,190 Cool. 83 00:05:15,220 --> 00:05:15,840 Capital. 84 00:05:15,880 --> 00:05:16,620 I. 85 00:05:16,810 --> 00:05:19,190 And that request for a 4. 86 00:05:19,210 --> 00:05:20,130 Not Found. 87 00:05:20,980 --> 00:05:21,220 OK good. 88 00:05:21,220 --> 00:05:24,900 Very last thing I want to show in this lesson is named locations. 89 00:05:25,060 --> 00:05:31,030 This being a concept which you might run into at some point and name location simply means assigning 90 00:05:31,030 --> 00:05:35,850 a name to a location context and using a directive such as Try files. 91 00:05:35,950 --> 00:05:42,760 Use that location by its name ensuring no revaluation has to happen on that final argument but instead 92 00:05:42,760 --> 00:05:49,270 just a definite call to the name location to name a location then more specifically this friendly underscore 93 00:05:49,270 --> 00:05:57,790 foro for use an at sign with a name at friendly underscore foro for doing the same on the location in 94 00:05:57,790 --> 00:05:59,080 order to you name it. 95 00:05:59,660 --> 00:06:00,640 Reload. 96 00:06:02,400 --> 00:06:03,850 And the browser. 97 00:06:03,930 --> 00:06:09,500 We get the same back to some DOD PRNG it's found and served.