From 3076d089c04bf08fb2519dcc81379db6d8794278 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sat, 20 Jan 2024 23:54:06 +0100 Subject: [PATCH] docs: optional host uri support for url redirects feature (#301) --- 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.
@@ -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: -- libgit2 1.7.2