Skip to content

Instantly share code, notes, and snippets.

@JustThomas
Created February 4, 2018 17:16
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save JustThomas/74d04d0ae542b6dab9495bce24c0741c to your computer and use it in GitHub Desktop.
Save JustThomas/74d04d0ae542b6dab9495bce24c0741c to your computer and use it in GitHub Desktop.
nginx: Remove double slashes from URLs

Put the following directives in your server block. nginx will then redirect URLs with double (or triple or multiple) slashes to the corresponding URL with a single slash.

merge_slashes off;
rewrite ^(.*?)//+(.*?)$ $1/$2 permanent;
@yuri-zubov
Copy link

yuri-zubov commented Feb 22, 2019

Another one

rewrite ^([^.]*?\/)\/+(.*)$ $1$2 permanent;

@kailashvele
Copy link

how to redirect it to no slash, just remove all the slashes?

@vgaicuks
Copy link

vgaicuks commented Aug 9, 2023

rewrite ^([^.]?/)/+(.)$ $1$2 permanent;

@yuri-zubov Thank you, your solution is the best it's avoiding many redirects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment