开发者

Problem with cyrillic characters in friendly url

开发者 https://www.devze.com 2023-02-08 21:37 出处:网络
Here\'s the thing. I have friendly urls like http://site.com/blog/read/мъдростта-на-вековете

Here's the thing. I have friendly urls like

http://site.com/blog/read/мъдростта-на-вековете

http://site.com/blog/read/green-apple

The last segment is actually the friendly title of the blog article. The problem is when I try to pass that segment to the database, the cyrillic fonts turn into something like %D1%8A%D0%B4%D1%80%D0%BE%D1%81%D1%8 and couldn't match the database record. In the address bar in my browser it looks normal (мъдростта-на-вековете) but if I choos开发者_JS百科e 'copy url location' the last segment again turns into these strange characters. I'm using CodeIgniter and everything is set to UTF-8.

Please help! :(


The text is just being encoded to fit the specification for URLs.

Echo out the data to a log to see what you are actually trying to pass to the database.

You should be able to decode it with urldecode.


The above answers are ok, but if you want to use routing with cyrillic it isn't enough. For example if you have http://site.com/блог/статия/мъдростта-на-вековете you will have to do something like this:

In config/routes.php: $route['блог/статия/(:any)'] = "blog/article/$1";

In system/core/URI.php , in the function _explode_segments(), you can change

$val = trim($this->_filter_uri($val));

to

$val = urldecode(trim($this->_filter_uri($val)));

This will solve the above problem plus controllers and functions.


Actually, Firefox is cheating you here: the URL actually is url-encoded, but is shown as if it wasn't. So copy-pasting and retrieving it on the server will have the URL encoded.

(Not sure if other browsers behave in the same way.)

0

精彩评论

暂无评论...
验证码 换一张
取 消