Mobile app version of vmapp.org
Login or Join
Correia994

: Nginx 301 redirects folders appending a slash Nginx is currently doing the following: example.com/folder 301 redirect to: example.com/folder/ How can I prevent it from doing this? Thanks.

@Correia994

Posted in: #301Redirect

Nginx is currently doing the following:


example.com/folder


301 redirect to:


example.com/folder/


How can I prevent it from doing this?

Thanks.

Edit: Added Nginx configuration


server {
server_name example.com; listen *:80;
listen [::]:80 ipv6only=on;
return 301 example.com$request_uri; }
server {
server_name example.com;
listen :80;
listen [::]:80;
root /home/usr/www;
index index.htm;
location ~ .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Correia994

2 Comments

Sorted by latest first Latest Oldest Best

 

@Hamaas447

Probably that is happening during the internal rewrite phase. To disable that, add into your server (or its inner) block:

rewrite ^(.+)/+$ permanent;

10% popularity Vote Up Vote Down


 

@Steve110

With your configuration the behavior your get is normal. It is because you have a folder named folder, apache prepends the trailing slash / and hides index.html (or index.php ) if that is not specified.

The only way to get rid of the slash at the end would be to force all request to go through 1 file (e.g. index.php) and then make your application routing logic work through that. But this is too much specific to what you are trying to accomplish to answer.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme