From 9127e702c0fbe9a5c3d95d586375a52ca8957140 Mon Sep 17 00:00:00 2001 From: ddelwig Date: Thu, 19 Mar 2026 14:14:37 +0100 Subject: [PATCH 1/2] Update how-to-use-nginx.md Adding nginx rewrite mapping to the docs. --- .../nginx/how-to-use-nginx.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/hypernode-platform/nginx/how-to-use-nginx.md b/docs/hypernode-platform/nginx/how-to-use-nginx.md index 23cf95c6..ddae684d 100644 --- a/docs/hypernode-platform/nginx/how-to-use-nginx.md +++ b/docs/hypernode-platform/nginx/how-to-use-nginx.md @@ -128,3 +128,46 @@ rewrite ^/fr/(.*)$ http://yourshop.fr/$1 permanent; This will also maintain subfolders and query strings (such as ). If the move is only temporary, you should use redirect instead of permanent. + +## Redirects using mapping + +The map directive allows you to define conditional logic outside of your main server block. This keeps your configuration: + +- Easier to read +- More scalable for large numbers of redirects +- More efficient than stacking multiple if statements + +You will define your redirects in two parts: + +1. A mapping configuration (placed in an `/data/web/nginx/http.*` file) +2. A rewrite rule (placed in a `/data/web/nginx/server.*` file) + +Step 1: Define the Redirect Mapping + +`/data/web/nginx/http.*` + +```nginx +map $uri $out_redirect { +~/the-location-you-want-to-redirect /new-location; +} +``` + +You can expand this map with multiple rules: + +```nginx +map $uri $out_redirect { +~/old-page /new-page; +~/blog/(.*) /articles/$1; +~/deprecated /; } +``` + +Step 2: Apply the Redirect in the Server Block + +`/data/web/nginx/server.*` + +```nginx +if ($out_redirect) { rewrite 301 $out_redirect; +} +``` + +Using `map` for redirects in NGINX provides a clean, scalable, and efficient way to manage URL rewrites. By separating logic from execution, your configuration remains easy to maintain even as the number of redirects grows. From bfb53bd5e2ca35e82141dbedb826daef905ee66e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 19 Mar 2026 14:17:02 +0100 Subject: [PATCH 2/2] Update docs/hypernode-platform/nginx/how-to-use-nginx.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- docs/hypernode-platform/nginx/how-to-use-nginx.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hypernode-platform/nginx/how-to-use-nginx.md b/docs/hypernode-platform/nginx/how-to-use-nginx.md index ddae684d..95a52d96 100644 --- a/docs/hypernode-platform/nginx/how-to-use-nginx.md +++ b/docs/hypernode-platform/nginx/how-to-use-nginx.md @@ -140,7 +140,7 @@ The map directive allows you to define conditional logic outside of your main se You will define your redirects in two parts: 1. A mapping configuration (placed in an `/data/web/nginx/http.*` file) -2. A rewrite rule (placed in a `/data/web/nginx/server.*` file) +1. A rewrite rule (placed in a `/data/web/nginx/server.*` file) Step 1: Define the Redirect Mapping