浏览器中的 URL 和特定于语言的字符


URLs in the browser and language specific characters

目前,我的URL具有特定于语言的字符(例如 http://example.com/kj øretøy/biler/vw-golf和 http://example.com//elektronikk/lydl øs-stue-pc_i3)时遇到了问题。当一个人复制网址时,我得到 http://example.com//kj%C3%B8ret%C3%B8y/biler/vw-golf和 http://example.com//elektronikk/lydl%C3%B8s-stue-pc_i3。我是带有SEF/永久链接的操作系统类,可以生成搜索引擎友好的URL。如何在浏览器的 URL 中显示特殊字符,如 æ、ø、å 分别显示为 ae、oe 和 aa?

提前谢谢。

编辑:谢谢。但我忘了提到这一切都是通过 Apache 重写完成的:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] 
</IfModule>

htmlentities 和 preg_replace 有一个小技巧。我通常使用这个自制功能:

function url_sanitize($url) {
    $url = strtolower(htmlentities(str_replace(' ', '-', $url)));
    $url = preg_replace('#&([a-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);#', '$1', $url);
    $url = preg_replace('#&([a-z]{2})(?:lig);#', '$1', $url);
    $url = preg_replace('#&[^;]+;#', '', $url);
    return $url;
}