Are there any downsides to using double-slashes in URLs?

☆樱花仙子☆ 提交于 2019-11-29 03:49:25
voithos

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.

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.

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.

Apache treats multiple slashes as a single slash. This affects things such as RewriteRules, e.g. if you have a rule like this:

RewriteRule ^user/(.*)/([0-9]+)$ /user.php?id=$2 [QSA,L]

That will catch links such as user/nomaD/500 but it will not catch user//500 since it treats that as user/500

So in other words, I don't think your setup will work since it will treat param1 as method and shift all the parameters left, unless they are of a specific type. I guess this doesn't affect your specific case, but in a lot of situations, this would be a downside to using //.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!