Skip to content

Instantly share code, notes, and snippets.

@KalobTaulien
Last active August 11, 2023 15:38
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KalobTaulien/eb5851ee42343aac614ab6e6cfe90245 to your computer and use it in GitHub Desktop.
Save KalobTaulien/eb5851ee42343aac614ab6e6cfe90245 to your computer and use it in GitHub Desktop.
Force lowercase paths using NGINX. Does not affect query params.
# On Ubuntu run `sudo apt-get install nginx-extras` for perl scripts to run
# `sudo service nginx restart` (verify it restarted properly)
# Add nginx.conf perl function; add yoursite.conf location
# /etc/nginx/nginx.conf
http {
# ...
perl_set $uri_lowercase 'sub {
my $r = shift;
my $uri = $r->uri;
$uri = lc($uri);
return $uri;
}';
}
# /etc/nginx/sites-enabled/yoursite.conf
server {
# ...
location ~ [A-Z] {
rewrite ^(.*)$ $scheme://$host$uri_lowercase;
}
# ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment