How to Remove Trailing Slash NGINX

Page 1

Remove Trailing Slash in NGINX

Open NGINX configuration file

Open terminal and run the following command to open NGINX server configuration file.

$ sudo vi /etc/nginx/nginx.conf

If you have configured separate virtual hosts for your website (e.g www.example.com), such as /etc/nginx/sites-enabled/website.conf then open its configuration with the following command

$ sudo vi /etc/nginx/sites-enabled/website.conf

Remove trailing slash

Add the following rewrite rule in server block as shown in bold. Replace example.com below with your domain name server { listen 80; server_name example.com; rewrite ^/(.*)/$ /$1 permanent;

}

Restart NGINX Server

Run the following command to check syntax of your updated config file.

$ sudo nginx -t

If there are no errors, run the following command to restart NGINX server.

$ sudo service nginx reload #debian/ubuntu

$ systemctl restart nginx #redhat/centos

https://ubiq.co/tech-blog/remove-trailing-slash-in-nginx/

for details
Thank You Visit

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.