Chapter 2 - Urls

I followed the book closely, but it just isn’t working. Looks like the only rule that is ever applied in Apache is


RewriteRule . index.php

My project directory is as follows (I’m using XAMPP): C:\xampp\htdocs\ppwk\

Here are the changes that I made inside:

protected/controllers/WebsiteController.php


class WebsiteController extends CController

{

    public function actionIndex()

    {

        echo 'index';

    }


    public function actionPage($alias)

    {

        echo "page is $alias";

    }

}

protected/config/main.php


        'urlManager'=>array(

            'urlFormat'=>'path',

            'rules'=>array(

                'home'=>'website/index',

                '<alias:about>'=>'website/page',

                'page/<alias>'=>'website/page',

            ),

        ),

htdocs/ppwk/.htaccess


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


#if a dir or file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


#otherwise forward it to index.php

RewriteRule . index.php

I guess the problem is in htaccess file, can someone tell me what the problem is?

Thanks.

htaccess looks OK. At least it’s the same htaccess everyone are using for Yii + Apache so htaccess itself should not be a problem.

Try adding ‘showScriptName’ => false to urlManager config and then open http://your.localhost.address/website/index

I hate when this happens, I had a different project open in my IDE, lol.

it’s working now.

hi samdark

i dont know why when i set showScriptName=>false , and i open site like =>localhost/app/cntr/act it shows 404 but with localhost/app/index.php/cntr/act it works?

Looks like your Apache is not reading htaccess.