Skip to content

URL Rewrites

SWS provides the ability to rewrite request URLs with pattern matching support.

URI rewrites are particularly useful with pattern matching (globs), 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.

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.

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

[advanced]

### URL Rewrites

[[advanced.rewrites]]
source = "**/*.{png,ico,gif}"
destination = "/assets/generic1.png"

[[advanced.rewrites]]
source = "**/*.{jpg,jpeg}"
destination = "/images/generic2.png"
Back to top