Yii Framework Forum: Issue with URL Management - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Issue with URL Management Rate Topic: -----

#1 User is offline   khonggiannet 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 21-May 09

Posted 10 February 2010 - 12:37 PM

I have 2 urls

?r=post/view&type=page&key=about : this is a "static" page
?r=post/view&type=article&key=first-article : this is an article


What I want is to rewrite post of page type and post of article type in diffirent types of URL. For ex,

/about.html (rewrite for ?r=post/view&type=page&key=about)
/article/first-article.html (reqrite for ?r=post/view&type=article&key=first-article)


(I have many other content types, not only page and article).

Is there any way to achieve that? I tried doing the following but it doesn't work at all:

'components'=>array(
	'urlManager'=>array(
           'urlFormat'=>'path',
	   'showScriptName'=>false,
	   'matchValue'=>true,
           'rules'=>array(
			'<type:[a-z0-9\-]+>/<key:[a-z0-9\-]+>.html' => 'post/view',		// other post view
			'<key:[a-z0-9\-]+>.html' => array('post/view', 'defaultParams'=>array('type'=>'page')),		// static page view
           ),
       ),

Everything having a beginning has an end!
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 10 February 2010 - 01:23 PM

Did you configure your .htaccess file?
Also, use 'urlSuffix'=>'.html' instead of ".html" in each rule.
0

#3 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 11 February 2010 - 04:41 PM

instead of using '<type:[a-z0-9\-]+>' try '<type:\w+>' (and the same for <key:...>)
0

#4 User is offline   khonggiannet 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 21-May 09

Posted 14 February 2010 - 08:36 AM

View PostOnman, on 11 February 2010 - 04:41 PM, said:

instead of using '<type:[a-z0-9\-]+>' try '<type:\w+>' (and the same for <key:...>)
No way! [a-z0-9\-]+ and \w+ are different fules!
           'rules'=>array(
                        '<type:[a-z0-9\-]+>/<key:[a-z0-9\-]+>.html' => 'post/view',             // other post view
                        '<key:[a-z0-9\-]+>.html' => array('post/view', 'defaultParams'=>array('type'=>'page')),         // static page view
           ),

You should try it, then you will know why it doesn't work. For ex, array('post/view', 'type'=>'page', 'key'=>'xyz') will produce url /page/xyz.html . That's not what I want. The problem here is that we cannot use the same route for 2 diferrent rules.
Everything having a beginning has an end!
0

#5 User is offline   khonggiannet 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 21-May 09

Posted 14 February 2010 - 08:37 AM

....................// sorry, please delete this duplicate post
Everything having a beginning has an end!
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 14 February 2010 - 09:30 AM

Before digging into the regex, let me ask one question: Why don't you use a separate action to serve your static pages? They are two different things that should also be separated in your controller. That would safe you a lot of hassle.
0

#7 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 15 February 2010 - 08:57 AM

Can you try this (change: the first rule):

'components'=>array(
	'urlManager'=>array(
		'urlFormat'=>'path',
		'showScriptName'=>false,
		'matchValue'=>true,
		'rules'=>array(
			'<type:article>/<key:[a-z0-9\-]+>.html' => 'post/view',		// other post view
			'<key:[a-z0-9\-]+>.html' => array('post/view', 'defaultParams'=>array('type'=>'page')),
												// static page view
           ),
       ),

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users