Skip to content

Instantly share code, notes, and snippets.

@Ashcon
Last active April 25, 2023 02:13
Show Gist options
  • Save Ashcon/7c8ff59bc6a9c970c44d50e8db41c5d5 to your computer and use it in GitHub Desktop.
Save Ashcon/7c8ff59bc6a9c970c44d50e8db41c5d5 to your computer and use it in GitHub Desktop.
New NARI nginx additions to test special URI cases and handle SPA client-side routing bug
map $request_uri $fixed_uri {
~*^/(.*)\s(.*)$ /$1%20$2;
}
map $request_uri $new_uri {
~*^(?!.*\.\w{1,5}$)(.*)[A-Z](.*)$ $scheme://$host${lowercase:$1}$2;
}
server {
location / {
# Check if the request URI needs to be fixed
if ($new_uri) {
# Redirect to the fixed URI
return 301 $new_uri;
}
# Check if the requested URI matches an existing file or directory
try_files $uri $uri/ @events;
# If no file or directory matches, redirect to the events route
location @events {
rewrite ^/(.*)$ /events/$1 last;
}
}
location /atmx-dip {
# Serve the index.html file if the requested file or directory does not exist
try_files $uri $uri/ /atmx-dip/index.html;
# Redirect all 404 errors to the index.html file
error_page 404 =200 /atmx-dip/index.html;
}
# Other server blocks and configuration directives
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment