URL Shortener
- create a generic list e.g.
short-urls
https://qsc.quasiris.de/console/list/playground with typeshort-urls
- configure columns:
shortUrl
- stringurl
- stringredirectCode
- string or longtype
default
- default - if no type is definedreplace
- replace the parameter like path, query
- add a new row
- shorUrl: my-short-url-documentation
- url: https://www.docs.qsc-search.de/docs/qsc-admin/admin/short-url/
- redirectCode: 302
- wait 5 minutes, because of caching
curl -i https://qsc.quasiris.de/api/v1/short-url/playground/short-urls/my-short-url-documentation
Replace
With the type replace
it is possible to create the Location url dynamically. Parameters from the source url can be replaced in
the Location url.
Example:
In this example we replace we use the path search
and the q
query parameter from the Reqeust url.
Request url: https://qsc.quasiris.de/api/v1/short-url/playground/short-urls/my-short-url-documentation/search?page=0&q=my+query
Configured url:q https://my-domain.com/${path0}?query=${q}
Location: https://my-domain.com/search?query=my+query
Paramters:
Parameter | Example | Comment |
---|---|---|
shortUrl | my-short-url-documentation | the short url from the path |
tenant | playground | the tenant code |
code | short-urls | the code of the list |
queryString | page=0&q=my+query | the complete queryString |
query.page | 0 | the value for the query parameter page |
query.q | my+query | the value for the query parameter q |
path0 | search | the first path part after the shortUrl |
pathAfterShortUrl | search | the whole path after the short url |
Limitations:
- multiple values for a query parameter are not supported. Just the first value is used
Rewrite with nginx
To use the short url's i a convenient way, a nginx rewrite can be used.
location /s/ {
rewrite ^/s/(.*)$ /api/v1/short-url/playground/short-urls/$1 last;
}
The url https://my-domain.com/s/my-short-url-documentation
is internally rewrited to
http://qsc.quasiris.de/api/v1/short-url/playground/short-urls/my-short-url-documentation