[英]what's with the trailing slashes in URLs?
So, there are a ton of questions here on SO about trailing slashes (help me remove, help me add, and so on).所以,这里有很多关于尾部斜杠的问题(帮我删除,帮我添加,等等)。 Mine relates to "help me remove" with an additional, "what is causing them?"
我的与“帮我移除”有关,另外还有“是什么导致了它们?”
I have a nodejs
+ expressjs
powered web site behind an nginx
proxy.我在
nginx
代理后面有一个由nodejs
+ expressjs
驱动的网站。 I have URLs without any trailing slashes, and yet, the browser is adding a trailing slash even though the Chrome/Safari developer tools or Firebug show the request without a trailing slash.我的 URL 没有任何尾部斜杠,然而,即使 Chrome/Safari 开发人员工具或 Firebug 显示没有尾部斜杠的请求,浏览器也会添加尾部斜杠。 So, in the debug tools I can see the request made (as intended) to
http://localhost:3000/resource?id=resource_id
but in the browser address bar that shows up as http://localhost:3000/resource/?id=resource_id
因此,在调试工具中,我可以看到(按预期)向
http://localhost:3000/resource?id=resource_id
发出的请求,但在显示为http://localhost:3000/resource/?id=resource_id
的浏览器地址栏中http://localhost:3000/resource/?id=resource_id
As mentioned above, I would like to not have the trailing slash added by the browser, and two, I would like to understand why that is happening in the first place.如上所述,我不想让浏览器添加尾部斜杠,还有两个,我想首先了解为什么会发生这种情况。
tl;dr This link might be helpful. tl;dr此链接可能会有所帮助。
Historically, it's common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to denote a file.
从历史上看,带有尾部斜杠的 URL 表示目录,而没有尾部斜杠的 URL 表示文件是很常见的。
To remove trailing slashes via nginx
simply add following statement inside your virtual host file in the server {}
block configuration:要通过
nginx
删除尾部斜杠,只需在server {}
块配置的虚拟主机文件中添加以下语句:
rewrite ^/(.*)/$ /$1 permanent;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.