[英]Codeigniter: UTF-8 in the URL bug
First, sorry about my bad english. 首先,对我的英语不好对不起。
Im using Codeigniter. 我正在使用Codeigniter。 When I create a dynamic address in UTF 8, I get strange characters.
当我在UTF 8中创建动态地址时,出现奇怪的字符。
The url look like this: domian.com/article/שלום#.T9H1U9WRGSo 网址看起来像这样:domian.com/article/שלום#。T9H1U9WRGSo
Instead of this: domain.com/article/שלום 代替此:domain.com/article/שלום
The links look okay: 链接看起来还可以:
<a href="http://www.domain.com/article/שלום">Text</a>
But after I click on the links, I get a redirect to here (in all the browsers except IE): 但是,单击链接后,我将重定向到此处(在除IE之外的所有浏览器中):
domain.com/article/שלום#.T9H1U9WRGSo domain.com/article/שלום#。T9H1U9WRGSo
Thank you all :) 谢谢你们 :)
OK, so the deal is that you cannot have non-ascii characters in your URL. 好的,所以要解决的是,您的URL中不能包含非ASCII字符。
The character has to be translated or encoded. 字符必须被翻译或编码。
Interestingly, if you look at a site like http://en.wiktionary.org/wiki/%D7%A9 the symbol will look correct in the URL because the browser is properly converting the % code to the ש symbol for you. 有趣的是,如果您浏览http://en.wiktionary.org/wiki/%D7%A9这样的网站,则该符号在URL中看起来将是正确的,因为浏览器已为您正确地将%代码转换为ש符号。
Edit: Some people report that this approach works 编辑:有人报告说这种方法有效
$hebrew = 'ס֑ס֒ס֓ס֔ס֕ס֖ס֗ס֘ס֙ס֚ס֛ס֜ס֝ס֞ס֟ס֠ס֡ס֢ס֣ס֤ס֥ס֦ס֧ס֨ס֩ס֪ס֫ס֬ס֭ס֮ס֯סְסֱסֲסֳסִסֵסֶסַסָסֹוֺסֻסּסֽ־סֿ׀סׁסׂ׃סׄסׅ׆סׇאבגדהוזחטיךכלםמןנסעףפץצקרשתװױײ׳״';
$config['permitted_uri_chars'] = $hebrew . ' a-z 0-9~%.:_\-';
(honestly, don't blame me if the alphabet is wrong :P ) (老实说,如果字母错误,请不要怪我:P)
I cannot speak for why Codeigniter may or may not redirect you to a #
URL, but URLs cannot contain non-ASCII characters. 我不能为什么笨可能会或可能不是你重定向到一个说话
#
网址,但网址不能包含非ASCII字符。 All non-ASCII characters need to be percent escaped using urlencode
: 需要使用
urlencode
对所有非ASCII字符进行百分比转义:
<a href="http://www.domain.com/article/<?php echo urlencode('שלום'); ?>">Text</a>
Since the browser should do this behind the scenes as a worst-case fallback, I can't say this will solve the problem, but at least it's more correct. 由于浏览器应该在最坏的情况下在后台执行此操作,因此我不能说这可以解决问题,但至少它是更正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.