是否建议在 URL 中使用非 ascii 字符? [英] Is it advisable to have non-ascii characters in the URL?

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

问题描述

我们目前正在开展一个 I18N 项目.我想知道在 URL 中使用非 ascii 字符有什么复杂性.如果不可取,​​有什么办法可以解决这个问题?

We are currently working on a I18N project. I am wondering what are the complications of having the non-ascii characters in the URL. If its not advisable, what are the alternatives to deal with this problem?

EDIT(响应 Maxym 的回答):该站点将是特定国家/地区的本地站点,我不必担心全世界的公众访问该站点.我知道从可用性的角度来看,真的很烦人.与此相关的其他技术问题是什么?

EDIT (in response to Maxym's answer): The site is going to be local to specific country and I need not worry about the world wide public accessing this site. I understand that from usability point of view, It is really annoying. What are the other technical problem associated with this?

推荐答案

使用IDNA.此外,您始终可以在 URL 中使用百分比编码(如 %20 用于空格).RFC 3986 推荐 UTF-8 编码结合百分比:

It is possible to use non-ASCII/non-Latin domain names using IDNA. Further, you can always use percent encoding (like %20 for space) in URLs. RFC 3986 recommends UTF-8 encoding combined with percents:

数据应首先编码为根据 UTF-8 八位字节字符编码;那么只有那些不对应的八位字节未保留集中的字符应该是百分比编码的.(...) 为了例如,字符 A 将是表示为A",字符带有 GRAVE 的拉丁文大写字母 A将表示为%C3%80",并且字符 KATAKANA LETTER A 会表示为%E3%82%A2".

the data should first be encoded as octets according to the UTF-8 character encoding; then only those octets that do not correspond to characters in the unreserved set should be percent-encoded. (...) For example, the character A would be represented as "A", the character LATIN CAPITAL LETTER A WITH GRAVE would be represented as "%C3%80", and the character KATAKANA LETTER A would be represented as "%E3%82%A2".

现代客户端(网络浏览器)能够在百分比编码和 Unicode 之间来回转换,因此 URL 以 ASCII 格式传输,但对用户来说看起来很漂亮.

Modern clients (web browsers) are able to transform back and forth between percent encoding and Unicode, so the URL is transferred as ASCII but looks pretty for the user.

确保您使用的网络框架/CMS 也能理解这种编码,以简化来自网站管理员/内容编辑器的 URL 输入.

Make sure you're using a web framework/CMS that understands this encoding as well, to simplify URL input from webmasters/content editors.

这篇关于是否建议在 URL 中使用非 ascii 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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