为什么 Apache 要删除多个斜杠?

发布于 2024-12-24 01:42:15 字数 334 浏览 2 评论 0原文

此 RewriteRule

RewriteRule ^test/(.*)$ test.php?url=$1

在此 URL

mysite.com/test//one///two////third// /

给了我这个结果

$1=url='one/two/third/'

我正在使用 easyphp 如果它很重要,我想知道 为什么 Apache 删除多个内部斜杠而不重定向到正确的网址?以及如何禁用或添加对此行为的重定向?

提前致谢

This RewriteRule

RewriteRule ^test/(.*)$ test.php?url=$1

On this URL

mysite.com/test//one///two////three///

Is giving me this result

$1=url='one/two/three/'

I'm using easyphp if it matters and I like to know why is Apache removing multiple slashes internally without redirecting to correcred URL? and how can I disable or add a redirect to this behaviour?

Thank in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭泣的笑容 2024-12-31 01:42:15

看来多重斜线是违反标准的。正如这篇文章,RFC 1630 说:

路径

URI 的其余部分遵循冒号,其格式取决于
方案。该路径的解释方式取决于
正在使用的协议。但是,当它包含斜杠时,这些
必须暗示层次结构。

/// 并不暗示分层结构 - 您将拥有空文件夹名称。由此我猜测 Apache 的行为是设计使然。 (使用多个斜杠也不是一个好主意,因为结果将是一个无效的 URL)。

我会使用不同的角色来代替。

It seems multiple slashes are against the standard. As pointed out in this post, RFC 1630 says:

PATH

The rest of the URI follows the colon in a format depending on the
scheme. The path is interpreted in a manner dependent on the
protocol being used. However, when it contains slashes, these
ust imply a hierarchical structure.

/// does not imply a hierarchical structure - you'd have empty folder names. From that I would guess that Apache's behaviour is by design. (Nor would it be a good idea to use multiple slashes, as the result would be an invalid URL).

I would use a different character instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文