Static Pages Under Subdirectories

Recently I came into a situation where I have to create static pages under different subdirectory. I was actually developing a site where user post articles by creating static pages instead of dynamic page. We want the url to look like instead of default like The directory structure was created like ‘site/pages/articles’ and all the articles pages were under articles subdirectory. After experimenting a lot with this issue, I finally get to the Yii IRC channel and got some help with user nicknamed ‘phpnode’ there. After working togetherly for some hours and experimenting on it, we came to the following solution:

  1. In controllers/SiteController.php file:

In function action() after the line:




add the following line:

'articles' => array('class' => 'CViewAction', 'basePath' => 'pages/articles')

here according to Yii documentation, basePath defaults to ‘pages’, so as we have created subdirectory ‘articles’ under ‘pages’ we should use ‘pages/articles’.

  1. Creating link on page:

Use the following code to create link for that article page:

Yii::app()->createUrl('site/articles', array('view' => 'myarticlepage'))

replace ‘myarticlepage’ with your page name under articles directory.

  1. In config/main.php under UrlManager create following entry:

'/article/<view>' => 'site/articles'

That’s all. :)


Zishan J.

Hi zishanj,

Thanks for sharing your solution. I almost went mad ecause in the urlManager was miss the first slash (/), i could’t figure out why it was not working. Pretty dumb.


instead of


Pretty sweet!!! You solution fixed it & my site works - check it out action