From 37c9ffc56b568aaadd0885268f2cb17292973bff Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Wed, 6 Jul 2022 22:20:31 +0200 Subject: [PATCH] docs: url rewrites feature [skip ci] --- docs/content/features/url-rewrites.md | 41 +++++++++++++++++++++++++++++++++++++++++ docs/mkdocs.yml | 1 + 2 files changed, 42 insertions(+) create mode 100644 docs/content/features/url-rewrites.md diff --git a/docs/content/features/url-rewrites.md b/docs/content/features/url-rewrites.md new file mode 100644 index 0000000..47d99ea --- /dev/null +++ b/docs/content/features/url-rewrites.md @@ -0,0 +1,41 @@ +# URL Rewrites + +**SWS** provides the ability to rewrite request URLs with pattern matching support. + +URI rewrites are particularly useful with pattern matching ([globs](https://en.wikipedia.org/wiki/Glob_(programming))), as the server can accept any URL that matches the pattern and let the client-side code decide what to display. + +## Structure + +The URL rewrite rules should be defined mainly as an [Array of Tables](https://toml.io/en/v1.0.0#array-of-tables). + +Each table entry should have two key/value pairs: + +- One `source` key containing a string _glob pattern_. +- One `destination` string containing the local file path. + +!!! info "Note" + The incoming request(s) will reach the `destination` only if the request(s) URI matches the `source` pattern. + +### 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. + +### Destination + +A local file path which must exist. It has to look something like `/some/directory/file.html`. It is worth noting that the `/` at the beginning indicates the server's root directory. + +## Examples + +```toml +[advanced] + +### URL Rewrites + +[[advanced.rewrites]] +source = "**/*.{png,ico,gif}" +destination = "/assets/generic1.png" + +[[advanced.rewrites]] +source = "**/*.{jpg,jpeg}" +destination = "/images/generic2.png" +``` diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 42e4759..72f9399 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -139,6 +139,7 @@ nav: - 'Worker Threads Customization': 'features/worker-threads.md' - 'Error Pages': 'features/error-pages.md' - 'Custom HTTP Headers': 'features/custom-http-headers.md' + - 'URL Rewrites': 'features/url-rewrites.md' - 'Windows Service': 'features/windows-service.md' - 'Platforms & Architectures': 'platforms-architectures.md' - 'Migration from v1 to v2': 'migration.md' -- libgit2 1.7.2