Last active
November 21, 2024 09:26
-
-
Save KalobTaulien/eb5851ee42343aac614ab6e6cfe90245 to your computer and use it in GitHub Desktop.
Force lowercase paths using NGINX. Does not affect query params.
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# /etc/nginx/nginx.conf | |
http { | |
# ... | |
perl_set $uri_lowercase 'sub { | |
my $r = shift; | |
my $uri = $r->uri; | |
$uri = lc($uri); | |
return $uri; | |
}'; | |
} |
This file contains hidden or 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
# /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