Skip to content

Instantly share code, notes, and snippets.

@wujku
Created April 3, 2020 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wujku/1f22d7945a724f80f70300a589159c5e to your computer and use it in GitHub Desktop.
Save wujku/1f22d7945a724f80f70300a589159c5e to your computer and use it in GitHub Desktop.
URI mapping with nginx
# example.local/blog?query=code -> example.local/news?query=code
# example.local/blog/?query=code -> example.local/news?query=code
map $uri $new_uri {
/blog /news;
/test /demo;
}
server {
listen 80;
default_type text/html;
server_name example.local;
if ($uri ~ ^/(.*)/$) {
return 301 $scheme://$host/$1$is_args$args;
}
if ($new_uri) {
return 301 $new_uri$is_args$args;
}
location / {
return 200 "Hello world!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment