mirror of
https://github.com/caddyserver/website.git
synced 2025-04-23 05:26:16 -04:00
Initial commit
This commit is contained in:
commit
03b6fddeb0
77 changed files with 7599 additions and 0 deletions
51
src/docs/markdown/caddyfile/directives/try_files.md
Normal file
51
src/docs/markdown/caddyfile/directives/try_files.md
Normal file
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
title: try_files (Caddyfile directive)
|
||||
---
|
||||
|
||||
# try_files
|
||||
|
||||
Rewrites the request URI path to the first of the listed files which exists in the site root. If no files match, no rewrite is performed.
|
||||
|
||||
|
||||
## Syntax
|
||||
|
||||
```
|
||||
try_files <files...>
|
||||
```
|
||||
|
||||
- **<files...>** is the list of files to try. The URI will be rewritten to the first one that exists. To match directories, append a trailing forward slash `/` to the path. All file paths are relative to the site [root](/docs/caddyfile/directives/root). Each argument may also contain a query string, in which case the query string will also be changed if it matches that particular file.
|
||||
|
||||
|
||||
## Expanded form
|
||||
|
||||
The `try_files` directive is basically a shortcut for:
|
||||
|
||||
```
|
||||
@try_files {
|
||||
file {
|
||||
try_files <files...>
|
||||
}
|
||||
}
|
||||
rewrite @try_files {http.matchers.file.relative}
|
||||
```
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
If the request does not match any static files, rewrite to an index/router file:
|
||||
|
||||
```
|
||||
try_files {path} /index.php
|
||||
```
|
||||
|
||||
Same, but adding the original path to the query string:
|
||||
|
||||
```
|
||||
try_files {path} /index.php?{query}&p={path}
|
||||
```
|
||||
|
||||
Same, but also match directories:
|
||||
|
||||
```
|
||||
try_files {path} {path}/ /index.php?{query}&p={path}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue