Are there any downsides to using double-slashes in URLs?(在 URL 中使用双斜杠有什么缺点吗?)
问题描述
我用 PHP 编写了自己的 MVC 框架,它使用以下格式的 url:
I've written my own MVC framework in PHP, which uses urls in the format of:
/controller/method/param1/param2/param...
我这样做是为了可以忽略默认"方法(默认情况下index()
),所以这会导致像 /controller//param1/param2/param 这样的 URL...
.例如,一个 URL:/view//panel-glide/3
将在 view
中调用 index('panel-glide', 3)
代码>控制器.
I've made it so that "default" methods can be ignored (by default index()
), so this results in URLs like /controller//param1/param2/param...
. For example, a URL of: /view//panel-glide/3
will call index('panel-glide', 3)
in the view
controller.
这很好用,但我担心搜索引擎或一些较旧的浏览器在看到双斜杠时可能会吓坏了,因为我认为我以前似乎从未使用过它们.
This works fine and dandy, but I'm concerned that search engines or some older browsers might freak out when they see the double slashes, as I don't think I've actually seem them ever be used before.
有没有人知道我在使用它时可能遇到的任何问题?
Is anyone aware of any issues I might come across by using this?
推荐答案
WebMasters 上已有一个答案讨论了 两个斜线.Apache 讨论的比较多,但是思路应该是通用的.
There is an existing answer on WebMasters that discusses the dangers of having two slashes. It discusses Apache a lot, but the ideas should be applicable generally.
本质上,我认为不推荐./foo/bar
和 /foo//bar
真的应该是两条完全不同的路径.每一条斜线都很重要,试图规避标准化的尝试肯定会反过来咬你.
In essence, I don't think it is recommended. /foo/bar
and /foo//bar
really should be two completely different paths. Each slash is significant, and attempts at circumventing that standardization are bound to come back to bite you.
正如答案中提到的,相对路径失败也存在非常真实的危险.一些浏览器会正确计算出来自 /foo/bar//baz
的相对路径 ../../fizz
是 /foo/bar/fizz
,而其他人会将双斜线视为单斜线,并选择 /foo/fizz
.
As is mentioned in the answer, there's also a very real danger of relative paths failing. Some browsers will correctly figure that a relative path ../../fizz
from /foo/bar//baz
is /foo/bar/fizz
, while others will treat the double slash as a single one, and opt for /foo/fizz
.
另外,我觉得它看起来很有趣.
Plus, I think it looks funny.
这篇关于在 URL 中使用双斜杠有什么缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 URL 中使用双斜杠有什么缺点吗?


- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01