Nginx How to Remove Trailing Slash

Valic —  July 31, 2011 — 1 Comment

For the sake of SEO is better to have one URL for each post or article on your site, like having two uris respond with the same content can lead to duplicate content and is penalized by search engines, especially Google, which is the largest by far.

Therefore, if you’re using Nginx and want to remove the trailing slash at the end of every URI in your site.

So if someone writes: will be automatically redirected to

Here is the code needed to put it in your nginx.conf.

rewrite ^/(.*)/$ /$1 permanent;

That goes in the server section so something like this:

server {
listen  :80;
rewrite ^/(.*)/$ /$1 permanent;

Nginx will handle the trailing slashes now.


Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

One response to Nginx How to Remove Trailing Slash

  1. ## remove any multislashes //
    if ($request_uri ~* “\/\/”) {
    rewrite ^/(.*)/$ /$1 permanent;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.