seo url with dash for blog demo tags

Hi all, first post here.

I’m about to finish my first project, which includes i18n, language selector and nice url (beautifying url)

My problem is with creating url in a widget much like the tag cloud included in the blog tutorial, but instead of the tag cloud, I want to display an Archive Menu by month-YYYY. Without i18n, all is fine, but when I add the language to the path, it breaks.

Here’s what I want to achive :

exemple.com/en/news/tag-name-with-dash

exemple.com/en/news/november-2011

Here’s how I do it :




config/main.php

...


'urlManager'=>array(

			'class'=>'application.components.UrlManager',

			'urlFormat'=>'path',

			'showScriptName'=>false,

            'rules'=>array( 

		'<language:(fr|en)>/videos'=>array('video/index', 'defaultParams' => array('channel' => '1'),

		'<language:(fr|en)>/videos/<channel:.*?>'=>array('video/index'),

                '<language:(fr|en)>/nouvelle/<id:\d+>/<title:.*?>'=>array('post/view'),

		'<language:(fr|en)>/news'=>array('post/index'),

	        '<language:(fr|en)>/news/<Post_page:\d+>'=>array('post/index', 'defaultParams' => array('Post_page' => '<Post_page>'),

                '<language:(fr|en)>/news/<tags:.*? >'=>array('post/index'),

                '<language:(fr|en)>/<controller:\w+>/<action:\w+>'=>array('<controller>/<action>'),

....

              ),







components/views/archiveMenu.php


...

$this->widget('zii.widgets.CMenu',array(

		'htmlOptions'=>array('class'=>'archiveMenu'),

		'items'=>array(

			array('label'=>'November 2011', 'url'=>array('nouvelles/november-2011'), 'active' => $tags == 'november-2010'?true:false),

...



And the result is :




 <a href="/news/november-2011/language/en">November 2011</a>



As mentionned before, without i18n and language code, url is generated correctly :




 <a href="/news/november-2011">November 2011</a>



It also works correctly if my tags are only one word, without dash (I’ll say hyphen also, cause when I do google search with dash, there’s a Yii extension named ‘Dash’ that always comes up and really doesn’t help me)




components/views/archiveMenu.php

...

$this->widget('zii.widgets.CMenu',array(

		'htmlOptions'=>array('class'=>'archiveMenu'),

		'items'=>array(

			array('label'=>'November', 'url'=>array('nouvelles/november'), 'active' => $tags == 'november'?true:false),

...




And strangely, if you look at my main.php config, I have done the same for videos/<channel> and it works perfectly with i18n and dash / hyphens

Note that if I enter directly in my browser’s address bar : exemple.com/en/news/november-2011 , it works, as I’ve modified my Post controller Index action with this :





...

$_GET['tags'] = preg_replace('/-/', ' ', $_GET['tags']);


...




I’ve tried playing around with the CMenu items url, doing things like

‘url’=>array(‘news’, array(‘tags’ => ‘november-2011’)

‘url’=>array(‘news’, array(‘tags’ => ‘november 2011’)

‘url’=>array(‘post/index’, array(‘tags’ => ‘november-2011’)

‘url’=>array(‘post/index’, array(‘tags’ => ‘november 2011’)

without much success…

Before you point it out, yes I know that tags aren’t semantically correct for what I want to achieve. Once this work out, I’ll change it to use the create time field…

Thank you, and sorry for the long post.

Well I’ve fixed this a while ago.

FYI, it was a problem with UrlManager rules order.