docs: optional host uri support for url redirects feature (#301)
Diff
docs/content/features/url-redirects.md | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
@@ -10,6 +10,7 @@ The URL redirect rules should be defined mainly as an [Array of Tables](https://
Each table entry should have the following key/value pairs:
- `host`: optional key containing a string hostname to be matched against the incoming host URI.
- `source`: key containing a string _glob pattern_.
- `destination`: local file path or a full URL with optional replacements (placeholders).
- `kind`: optional number containing the HTTP response code (redirection).
@@ -17,6 +18,13 @@ Each table entry should have the following key/value pairs:
!!! info "Note"
The incoming request(s) will reach the `destination` only if the request(s) URI matches the `source` pattern.
### Host
Optional `host` redirect entry to be matched against the incoming host URI. If a `host` redirect setting is specified then SWS will attempt to match the value against the incoming URI host (request), applying the required redirect entry or ignoring it otherwise.
!!! tip "www to non-www redirects"
The host entry allows for instance to perform www to non-www redirects or vice versa (see example below).
### Source
The source is a [Glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) that should match against the URI that is requesting a resource file.
@@ -34,8 +42,7 @@ It could look like `/some/directory/file.html`. It is worth noting that the `/`
#### Replacements
Additionally, a `destination` supports replacements for every Glob pattern group that matches against the `source`.
Replacements order start from `0` to `n` and are defined with a dollar sign followed by an index (Glob pattern group occurrence).
The replacement order starts from `0` to `n` and is defined with a dollar sign followed by an index (Glob pattern group occurrence).
!!! tip "Group your Glob patterns"
When using replacements, also group your Glob pattern by surrounding them with curly braces so every group should map to its corresponding replacement.<br>
@@ -76,6 +83,14 @@ source = "**/{*}.{jpg,jpeg,svg}"
## For example, the destination will result in `http://localhost/assets/abcdef.jpeg`
destination = "http://localhost/assets/$1.$2"
kind = 301
# d. Simple route redirect using the `host` option
# to perform www to non-www redirection.
[[advanced.redirects]]
host = "www.domain.com"
source = "/{*}"
destination = "https://domain.com/$1"
kind = 301
```
If you request something like: