URL 中的 Unicode 字符 [英] Unicode characters in URLs

查看:37
本文介绍了URL 中的 Unicode 字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 2010 年,您会在大型门户网站中提供包含 UTF-8 字符的网址吗?

In 2010, would you serve URLs containing UTF-8 characters in a large web portal?

根据 RFC 上的 URL 禁止使用 Unicode 字符(请参阅此处).它们必须经过百分比编码才能符合标准.

Unicode characters are forbidden as per the RFC on URLs (see here). They would have to be percent encoded to be standards compliant.

不过,我的主要观点是提供未编码字符的唯一目的是获得漂亮的 URL,因此百分比编码已经过时了.

My main point, though, is serving the unencoded characters for the sole purpose of having nice-looking URLs, so percent encoding is out.

无论 RFC 怎么说,所有主要浏览器似乎都可以正确解析这些 URL.不过,我的总体印象是,离开网络浏览器的域时它会变得非常不稳定:

All major browsers seem to be parsing those URLs okay no matter what the RFC says. My general impression, though, is that it gets very shaky when leaving the domain of web browsers:

  • URL 被复制并粘贴到文本文件、电子邮件,甚至是具有不同编码的网站中
  • HTTP 客户端库
  • 异国情调的浏览器、RSS 阅读器

我的印象是否正确,这里会出现问题,因此如果您为非技术受众提供服务,这不是一个实用的解决方案(还),重要的是您的所有链接即使被引用和传递也能正常工作?

Is my impression correct that trouble is to be expected here, and thus it's not a practical solution (yet) if you're serving a non-technical audience and it's important that all your links work properly even if quoted and passed on?

有什么神奇的方法可以在 HTML 中提供漂亮的 URL 吗

Is there some magic way of serving nice-looking URLs in HTML

http://www.example.com/düsseldorf?neighbourhood=Lörick

可以复制+粘贴完整的特殊字符,但在旧客户端中重新使用时可以正常工作吗?

that can be copy+pasted with the special characters intact, but work correctly when re-used in older clients?

推荐答案

使用百分比编码.现代浏览器将负责显示和粘贴问题并使其易于阅读.例如http://ko.wikipedia.org/wiki/위키백과:대문

Use percent encoding. Modern browsers will take care of display & paste issues and make it human-readable. E. g. http://ko.wikipedia.org/wiki/위키백과:대문

当你在 Firefox 中复制这样的 url 时,剪贴板将保存百分比编码形式(这通常是一件好事),但如果你只复制它的一部分,它将保持未编码状态.

when you copy such an url in Firefox, the clipboard will hold the percent-encoded form (which is usually a good thing), but if you copy only a part of it, it will remain unencoded.

这篇关于URL 中的 Unicode 字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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