URL编码中是否在目录名称中使用下划线? [英] URL Encoding with Underscores in a Directory Name?

查看:298
本文介绍了URL编码中是否在目录名称中使用下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在工作时遇到了一个奇怪的争论,对此我可能是错的,所以这就是我要问的原因.

We've run into an odd argument where I work, and I may be wrong on this, so this is why I am asking.

我们的软件将目录输出到Apache服务器,该服务器将目录名称中的下划线替换为%5F.

Our software outputs a directory to an Apache server that replaces an underscore with a %5F in the name of the directory.

例如,如果目录的名称在我们的软件中以字符串形式列出,则为:"andy_test",但是当软件将目录输出到Apache服务器时,它将变为"andy%5Ftest".不幸的是,当您访问服务器上的URL时,它最终变成了"andy%255Ftest".

For instance if the name of the directory was listed as a string in our software it would be: "andy_test", but then when the software outputs the directory to the Apache server, it would become "andy%5Ftest". Unfortunately, when you access the url on the server it ends up becoming "andy%255Ftest".

这在某种程度上对我来说似乎是错误的,进展再次是:

Somehow this seems wrong to me, once again the progression is:

  1. andy_test< ;-(作为软件中的字符串)
  2. andy%5Ftest< ;-(在服务器上列为目录)
  3. andy%255Ftest<-((当从Web浏览器中调用与服务器上的URL相同的目录时,必须使用.)

我假设%5"编码为下划线,而%25"编码为%".

I'm assuming that "%5" is encoding for underscore, and that "%25" is encoding for "%".

现在在我看来,目录名称应在服务器上列出的方式只是普通的andy_test,如果您使用的是编码的URI,则可能最终以"andy%5Ftest"访问apache服务器上的目录.

Now it would seem to me that the way that the directory name should be listed on the server would be just plain andy_test and if you were using an encoded URI then maybe you would end up with the "andy%5Ftest" to access the directory on the apache server.

我问了一下后端的人,他们说他们只是:编码不是字母或数字的任何东西.

I asked the guys on the backend about it, and they said that they were just: "encoding anything that was not a letter or a number.

所以我想我对此有些困惑.您能告诉我谁是正确的,并指导我了解为什么吗?

So I guess I'm a bit confused on this. Can you tell me who is right, and direct me to some information on why?

推荐答案

在创建目录名称时,请勿对它们进行编码(如建议的那样).编码应仅在将其分发给浏览器的最后阶段进行.这就是为什么要使用双精度"编码的原因:%25是%,下划线的第一个编码剩下5F.

You should not encode the directory names as you create them (as you suggested). Encoding should only happen at the last stage where it is handed out to the browser. That's why you are ending up with 'double' encoding: %25 is % and 5F is the leftover from the first encoding of underscore.

此外,请注意,您无需根据 rfc1738来对下划线进行编码a>.

Also, note that you don't need to encode underscores according to rfc1738.

2.2. URL字符编码问题

2.2. URL Character Encoding Issues

...

因此,只有字母数字,特殊字符"$ -_.+!*'(),"和 可以使用用于保留目的的保留字符 在URL中未编码.

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

这篇关于URL编码中是否在目录名称中使用下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆