Created
April 3, 2020 12:30
-
-
Save wujku/1f22d7945a724f80f70300a589159c5e to your computer and use it in GitHub Desktop.
URI mapping with nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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