I am running a server on nginx with PHP-FastCGI. Currently I have it setup so that it removes trailing slashes from my URLs and issues a 301 redirect. However, when I visit a directory that exists,"err_too_many_redirects"(if I try to check that such kind of links like site.com/images/ or other directory link return 403 code ), My server block looks like this:
server {
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
rewrite ^/(.*)/$ /$1 permanent;
error_page 404 403 /404.html;
location = /404.html {
internal;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
internal;
}
location / {
try_files $uri $uri.html $uri/ $uri/index.html $uri/index $uri/ =404;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
Could anyone help me to find soultion for this problem?
$uri/term together with yourrewriterule will create a loop. Try:try_files $uri $uri.html $uri/index.html $uri/index =404;