Content management system Yii中的动态SEO友好url

Content management system Yii中的动态SEO友好url,content-management-system,yii,seo,Content Management System,Yii,Seo,我想在yii中使用自定义动态seo友好URL 我读过各种各样的文章,他们都说了同样的话 这是我迄今为止设法找到的,它不适合我的需要: 'urlManager'=>array( 'urlFormat'=>'path', 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '

我想在yii中使用自定义动态seo友好URL

我读过各种各样的文章,他们都说了同样的话

这是我迄今为止设法找到的,它不适合我的需要:

    'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'urlManager'=>数组(
“urlFormat'=>“路径”,
'规则'=>数组(
“/”=>“/视图”,
"/

其中concurs-castiga-o-invitatie-de-trei-zile-de-festival-la-bestfest-2012是文章标题

这就是行动

2是数据库id


882是文章id

让我用我的评论作为答案。你仍然需要自己实现一些东西,但这应该让你开始:

class MyRule extends CBaseUrlRule
{
  public function parseUrl($oManager, $oRequest, $sPathInfo, $sRawPathInfo)
  {
    // Extract database Id and article Id from $sPathInfo and perhaps put it in $_REQUEST
    if ("url isn't SEO thingy")
      return FALSE:        
    return 'articles/index';
  }

  public function createUrl($oManager, $sRoute, $aParameters, $sAmpersand)
  {
     if ("i have an SEO item to show")
       return "/however you want to assemble your URL"; 
     return FALSE; 
  }
}
上面的示例假设您通过articles控制器(操作索引)路由所有内容

添加到配置就是将以下内容添加到规则中:

'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            array('class' => 'MyRule'),
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'urlManager'=>数组(
“urlFormat'=>“路径”,
'规则'=>数组(
数组('class'=>'MyRule'),
“/”=>“/视图”,
'//'=>'/',
'/'=>'/',

您可能最终不得不编写自己的UrlRule类并将其首先放入规则数组中。如果您在URL中不使用任何控制器/操作,则可能是这样,或者让Yii通过默认控制器/操作路由所有内容并在那里解析。我编写了自己的URL路由器,但我选择在url,这使它更容易。
'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            array('class' => 'MyRule'),
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',