Trailing slash

本文探讨了URL中尾部斜杠的使用规范及其重要性,解释了尾部斜杠通常指示目录,而无尾斜杠则表示文件。文章强调了资源URI的正确构造方式,即只有叶资源(没有下级资源的资源)不应包含尾部斜杠,并推荐了在接收到不带尾斜杠的请求时进行永久重定向至带有尾斜杠的URI的做法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Trailing Slash

common case

It’s common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to denote a file:

 http://example.com/sub/ (trailing  slash ,conventionally a directory)
 http://example.com/sub (without trailing slash,conventionally a file)

In relative urls

  • child relative to /parent/ is /parent/child

  • child relative to /parent is /child

References

When should I use a trailing slash in my urls

To slash or NOT to slash

Why trailing slashes on URLS are important!

  • Only leaf resources (resources with no subordinates) should lack a trailing slash in their URI.
  • If a request is received without a trailing slash, then do a permanent redirect to the URI with the trailing slash.
  • Use relative paths wherever possible (DRY principle).
  • Remember to include the trailing slash in query URIs.
  • Don’t do anything that would prevent consumers of your API using relative URIs.

References

Why trailing slashes on URLS are important

转载于:https://www.cnblogs.com/rosendolu/p/10180083.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值