Solved trailing slash issue with Nginx server

I added following block in my nginx.conf file. You should add following lines in your server { } block.

We Solved trailing slash issue with Nginx server

If you want use URL without ending trailing slash. then use following code.
#code block added for trailing slash issue solving
server_name_in_redirect off;
optimize_server_names off;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_access group:rw all:r;
create_full_put_path on;

if (-d $request_filename) { rewrite ^(.*[^/])$ $1/ break; }
if ($request_method = MKCOL) { rewrite ^(.*[^/])$ $1/ break; }
Above code will check if folder is present then fetch data from there. If you have some idea about MKCOL then you will know above code in better way.
If Your problem will not solved from above code then use following code.
#here we are adding trailing slash end of Url
if ($request_uri ~* “^[\w\-\/]+[^\/?]$”) {rewrite ^(.*)$ $scheme://$host$1/ permanent;}
This will add the ending slash to your url.
Viman Nagar Rd, Viman Nagar, पुणे, Maharashtra, India

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.