Skip to content

Commit

Permalink
docs: optional host uri support for url redirects feature (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Jan 20, 2024
1 parent dedefc5 commit 3076d08
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions docs/content/features/url-redirects.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ 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).

!!! 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.
Expand All @@ -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>
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3076d08

Please sign in to comment.