index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2024-01-20 22:54:06.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2024-01-20 22:54:06.0 +00:00:00
commit
3076d089c04bf08fb2519dcc81379db6d8794278 [patch]
tree
bf1509ed37fbcd29065043d868ddde4d7bad482a
parent
dedefc5eebf510b4d43059ad72d7f0d5d072b2bb
download
3076d089c04bf08fb2519dcc81379db6d8794278.tar.gz

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(-)

diff --git a/docs/content/features/url-redirects.md b/docs/content/features/url-redirects.md
index da32d89..4626722 100644
--- a/docs/content/features/url-redirects.md
+++ b/docs/content/features/url-redirects.md
@@ -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: