【问题标题】:How to convert domain names with greek characters to an ascii URL?如何将带有希腊字符的域名转换为 ascii URL?
【发布时间】:2010-09-16 13:07:07
【问题描述】:

例如:

在 Firefox 中输入 παιχνιδια.com 时,会自动转换为 xn--kxadblxczv9d.com

请推荐一个进行这种转换的工具。


其中一个最简单的是this。同时转换和检查可用性。

【问题讨论】:

标签: url character-encoding ascii punycode


【解决方案1】:

如果您想在浏览器中执行此操作,请将 this answer 中的代码保存为 puny.js 并将下面的代码保存为 puny.html,然后加载浏览器中的文件。

<html>
    <title>Punyconverter</title>
    <script type="text/javascript" src="puny.js"></script>
    <style type="text/css">
        input {width:300px;}
        label {width:100px; display:inline-block;}
    </style>
    <script type="text/javascript">
        onload = function( ) {
            var ASCII = document.getElementById("ASCII");
            var Unicode = document.getElementById("Unicode");
            var Input = document.getElementById("Input");

            Input.onkeyup=function(){
                ASCII.value = punycode.ToASCII( this.value);
                Unicode.value = punycode.ToUnicode( this.value);
            }
        };
    </script>
</html>
<body>
    <h1>Convert puny coded IDN</h1>
    <div><label for="Input">Input</label><input id="Input" type="text"></div>
    <div><label for="ASCII">ASCII</label><input id="ASCII" type="text" readonly="readonly"></div>
    <div><label for="Unicode">Unicode</label><input id="Unicode" type="text" readonly="readonly"></div>
</body>

【讨论】:

    【解决方案2】:

    您可以使用任何支持“Libidn”的工具。快速搜索显示SimpleDNS 可能对您有所帮助。

    网上有大量的 IDN 转换器,如果你觉得够用,你可以使用其中的one

    【讨论】:

      【解决方案3】:

      Internationalized domain name(即具有非 ASCII 字符的域名)使用Punycode 系统进行编码。

      【讨论】:

        【解决方案4】:

        您对 IDNA with Python 进行编码和解码:

        >>> print u'παιχνιδια'.encode('idna')
        xn--mxaaitabzv9d
        >>> print 'xn--mxaaitabzv9d'.decode('idna')
        παιχνιδια
        

        【讨论】:

          【解决方案5】:

          Perl 中的标准模块在 Apache 中也可以通过 URI 模块来实现。

          use URI;
          #insert sitename in next:
          $sitename = "..";
          my $uri = URI->new( $sitename,'http');
          if ($uri->scheme) { print $uri; }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-04-20
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多