Digg 按钮拒绝编码的 url
我写了一个 php 网站(它仍然是一个原型),并在上面放置了一个 Digg 按钮。这很简单,但是......
官方手册说:“URL 必须被编码”。我用 urlencode() 做到了这一点。 urlencode 之后,我的 URL 看起来像这样:
http%3A%2F%2Fwww.mysite.com%2Fen%2Fredirect.php%3Fl%3Dhttp%3A%2F%2Fwww.othersite.rs%2FNews%2FWorld%2F227040%2FRusia-Airplane-crashed%26N%3DRusia%3A+Airplane+crashed
到目前为止,一切都很好,但是当我想将该 URL 提交到 Digg 时,它被识别为无效 URL:
http://www.mysite.com/en/redirect.php?l=http://www.othersite.rs/News/World/227040/Rusia-Airplane-crashed&N=Rusia:+Airplane crashed
如果我在“Airplane”和“crashed”之间放置一个“+”(位于链接末尾),然后 Digg 就可以毫无问题地识别它!
请帮忙,这个奇怪的问题正在杀死我的脑细胞!
PS 出于此答案的目的,网址已更改(更改为不存在的网址),因为在原始版本中涉及非英语网站。
I wrote a php site (it's still a prototype) and I placed a Digg button on it. It was easy but...
The official manual says: "the URL has to be encoded". I did that with urlencode(). After urlencode, my URL looks like this:
http%3A%2F%2Fwww.mysite.com%2Fen%2Fredirect.php%3Fl%3Dhttp%3A%2F%2Fwww.othersite.rs%2FNews%2FWorld%2F227040%2FRusia-Airplane-crashed%26N%3DRusia%3A+Airplane+crashed
So far it's good, but when I want to submit that URL to Digg, it is recognized as an invalid URL:
http://www.mysite.com/en/redirect.php?l=http://www.othersite.rs/News/World/227040/Rusia-Airplane-crashed&N=Rusia:+Airplane crashed
If I place a "+" between "Airplane" and "crashed" (at the end of the link), then Digg recognizes it without any problems!
Please help, this bizarre problem is killing my brain cells!
P.S. For purpose of this answer, urls are changed (to nonexisting ones) because, in the original, non-english sites are involved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
urlencode()
编辑后,也对生成的加号进行编码:或者,您可以先用
+
替换 URL 中的空格,然后用urlencode()
结果:如果您自己的站点首先需要对查询字符串中的参数进行编码,那么您就不会有问题(因为原始站点中不会有未编码的空间)网址)。
After you've
urlencode()
ed it, encode the resulting plus signs as well:Or alternatively, you could replace spaces in your URL with
+
first, and thenurlencode()
the result:If your own site required the parameters in the query string to be encoded in the first place, you wouldn't have the issue (since there wouldn't be an unencoded space in the original URL).