0

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?

2
  • The $uri/ term together with your rewrite rule will create a loop. Try: try_files $uri $uri.html $uri/index.html $uri/index =404; Commented Jun 13, 2018 at 12:40
  • Thankyou it works for me. Cheers! Commented Jun 13, 2018 at 14:12

1 Answer 1

1

The $uri/ term together with your rewrite rule will create a loop. Try:

try_files $uri $uri.html $uri/index.html $uri/index =404;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.