在 url、codeigniter、seo 中使用 utf 8

use utf 8 in url, codeigniter ,seo

我正在建设一个网站,我想在 url 中使用 utf 8 个字符,我在一些地方看过,但我没有得到我需要的答案,所以我对此几乎没有疑问。

我正在使用 codeigniter,我正在建设的网站有一篇文章,我想在 url

中发送文章标题(非英文)

域。com/ctrl/articles/articleTitle(非英文)

  1. 使用这种 url 是否对 SEO 有利,以防我的访问者进行非英语搜索
  2. 我该怎么做?

谢谢大家的回答。

这里的问题不是SEO。 Google 不会对 url 中的 utf8 字符挑剔,尽管非常旧的浏览器存在兼容性问题。

如果您正在谈论例如只有几个额外字符的斯堪的纳维亚语言,google 足够聪明来转换搜索词,例如其中包含 'bär' 以匹配名为 'bar' 的页面,反之亦然。因此,对于这种类型的语言,将 utf8 字符放入 url 可能不值得。但是如果你说的是中文什么的,那么这里有一个方法。

问题是 codeigniter 使用 url 来确定要执行的 class 和函数,并且仅限于 php5 中的 a-zA-Z_(我认为) .这个人说这不是一件容易的事,但详细介绍了一种似乎有效的方法。

https://ellislab.com/forums/viewthread/146840/#717001

You can enable UTF-8 characters by entering them into the allowed_chars_list in config.php then set up routes for your Foreign URL segments, or by patching the router to convert UTF-8 characters to their nearest a-z characters perhaps?

基本上重写 utf8 urls,以便在内部将它们转换为普通字符,从而找到正确的函数。

如果你把这一行放在你的控制器构造函数中,它会强制一切都变成 utf-8

class Article extends CI_Controller {

  function __construct() {

    parent::__construct();

    // set all to utf-8 
    $this->output->set_header('Content-Type: text/html; charset=utf-8');

  } 

// controller methods etc 

链接将在您的视图文件中输出——这确保您的所有文本(包括链接)都将以 utf-8 编码输出。另一方面是默认情况下 codeigniter 在 url 中不允许出现的字符——在 application/config/config.php 中查看

$config['permitted_uri_chars']