最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

nginx - In Safari, requests without a trailing slash are not redirected to those with a trailing slash - Stack Overflow

programmeradmin0浏览0评论

I am serving static content with Nginx, and I have a question about the behavior of requests without a trailing slash. While everything works fine in Chrome, Safari behaves differently.

When I access in Safari, the following error is displayed:

Cannot Open Page
Safari can’t open the page “” because the server unexpectedly dropped the connection. This sometimes occurs when the server is busy. Wait for a few minutes, and then try again.

The URL remains , and adding a trailing slash manually still results in the same error. However, if I open a new tab and access / directly, the page loads without any issues.

Here’s my Nginx configuration:

location /test {
  root /var/www/html;
  try_files $uri $uri/ =404;
}

From my understanding, Nginx should redirect requests without a trailing slash to the trailing slash version of the URL, but it seems like that is not happening.

In Chrome, the redirection works as expected, and the page is displayed correctly. However, I noticed that Chrome makes two requests: one to and another to /. The second request responds with a 307 status code, with the Location header pointing to /. This HTTP-to-HTTPS redirection is a bit concerning as well.

What can I do to make Safari handle this situation properly and load the page correctly? Any advice or insights would be greatly appreciated!

I expected Nginx to redirect requests without a trailing slash to the trailing slash version of the URL (e.g., /test/foo/test/foo/) as it normally does. I tried accessing the URL in Safari, assuming it would work the same way it does in Chrome. However, in Safari, the request fails with a connection error, and no redirection happens. In Chrome, the redirection works properly. I also tried adding a trailing slash manually in Safari (/test/foo/), but it still resulted in the same error unless accessed from a new tab. I expected the behavior to be consistent across browsers.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论