| | 161 | Another usage example |
|---|
| | 162 | ~~~~~~~~~~~~~~~~~~~~~ |
|---|
| | 163 | |
|---|
| | 164 | As you can see, getting the hang of how authentication works is pretty |
|---|
| | 165 | easy. Let's ilustrate another easy example. How to serve PHP files, |
|---|
| | 166 | both from a protected location and an unprotected one? |
|---|
| | 167 | |
|---|
| | 168 | Let's assume our locations are targets are: |
|---|
| | 169 | - /unprotected/*.php |
|---|
| | 170 | - /protected/*.php |
|---|
| | 171 | |
|---|
| | 172 | Well... this would be really easy. You just have to remember that |
|---|
| | 173 | rules are evaluated from top to bottom, and the evaluation proceeds |
|---|
| | 174 | until a final rule is matched. |
|---|
| | 175 | |
|---|
| | 176 | This means that we would only have to be careful with the order of our |
|---|
| | 177 | rules, and it would be as simple as setting a couple of rules: |
|---|
| | 178 | |
|---|
| | 179 | - The first one, of type `Directory` applied to the path |
|---|
| | 180 | `/protected`. This would be the top rule, should use one of the |
|---|
| | 181 | authentication mechanisms mentioned above and should not be set as |
|---|
| | 182 | _FINAL_. |
|---|
| | 183 | |
|---|
| | 184 | - The second one, of type `Extension` would apply to `php` files and |
|---|
| | 185 | should be configured as according to the link:cookbook_php.html[PHP |
|---|
| | 186 | recipe]. This one should be a _FINAL_ rule. |
|---|
| | 187 | |
|---|
| | 188 | And this would be more than enough. The files from the secure location |
|---|
| | 189 | would match the first rule and the authentication would be |
|---|
| | 190 | required. In case it was successful, not being a final rule, the |
|---|
| | 191 | request would proceed to the second rule. Once there, the regular |
|---|
| | 192 | processing of PHP files would take palce. This one is a _FINAL_ rule, |
|---|
| | 193 | so the rule evaluation would stop. |
|---|
| | 194 | |
|---|
| | 195 | In case the PHP files were not being requested from the secured |
|---|
| | 196 | directory, just the second rule would apply. |
|---|
| | 197 | |
|---|