在网址中使用双斜杠是否有不利之处? [英] Are there any downsides to using double-slashes in URLs?
问题描述
我已经用PHP编写了自己的MVC框架,该框架使用以下格式的网址:
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.
这篇关于在网址中使用双斜杠是否有不利之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!