: 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.
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;
}
}
More posts by @Correia994
2 Comments
Sorted by latest first Latest Oldest Best
Probably that is happening during the internal rewrite phase. To disable that, add into your server (or its inner) block:
rewrite ^(.+)/+$ permanent;
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.