$this->redirect() creates wrong URL

I’m using Yii 1.1.16 on CentOS with Apache/MySql

I have the following in my main.php config




...

'urlManager'=>array(

            'urlFormat'=>'path',

                        'showScriptName'=>false,

                        'caseSensitive'=>false,

            'rules'=>array(

                        'admin/<_c>'=>'<_c>/admin',

                        'admin/<_c>/page/<page:\d+>'=>'<_c>/admin',

                        'admin/<_c>/<_a:(update|create)>/*'=>'<_c>/<_a>',

...



Yet, when I execute this


$this->redirect(array('categories/admin'));

… it takes me to

mydomain.com/admin/categories/admin

shouldn’t it take me to

mydomain.com/admin/categories

?

What am I missing?

Are you calling this from the admin module? [size=2]Because the module id gets prefixed… check the doc for createUrl() - [/size]http://www.yiiframework.com/doc/api/1.1/CController#createUrl-detail

try it like so


$this->redirect(array('admin/categories'));

module name should be first

No, there is no admin module. I’m calling this from CategoriesController.php

When I did that it generates:

mydomain.com/admin/admin/categories

can you paste your entire config/main.php

Use:




$this->redirect(array('/admin/categories'));



You need the leading forward slash.

More details here, specifically:

When I do that it takes me to

mydoinain.com/admin/admin/categories

also, shouldn’t it be ‘categories/admin’?

I am in the categories controller and am trying to call the admin action … I don’t understand what any of this has to do with modules?




<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

        'name'=>'My Web Application',

        'defaultController'=>'Pages',


        // preloading 'log' component

        'preload'=>array('log'),


        // autoloading model and component classes

        'import'=>array(

                'application.models.*',

                'application.components.*',

        ),


	// application components

        'components'=>array(

           'db'=>array(

            'class'=>'CDbConnection',

            'connectionString'=>'mysql:host=localhost;dbname=xxx',

            'username'=>'xxx',

            'password'=>'xxx',

            'emulatePrepare' => true,

                #'enableProfiling' => true

),

          	'log'=>array(

                        'class'=>'CLogRouter',

                        'routes'=>array(

                                array(

                                      	'class'=>'CFileLogRoute',

                                        'levels'=>'error, warning',

                                ),

                                array(

                                      	'class'=>'CProfileLogRoute',

                                        'levels'=>'trace, info',

                                ),


                        ),

                ),

                'urlManager'=>array(

            'urlFormat'=>'path',

                        'showScriptName'=>false,

                        'caseSensitive'=>false,

            'rules'=>array(

                        'admin/<_c>'=>'<_c>/admin',

                        'admin/<_c>/page/<page:\d+>'=>'<_c>/admin',

                        'admin/<_c>/<_a:(update|create)>/*'=>'<_c>/<_a>',

                        'admin'=>'reviews/admin',

                        'site/click'=>'site/click',

                        'site/promote/<siteLink:[a-zA-Z0-9-\.]+>/*'=>'site/promote',

                        'site/badge/<siteLink:[a-zA-Z0-9-\.]+>/*'=>'site/badge',

                        'site/balances'=>'site/balances',

                        'site/burn'=>'site/burn',

                        'site/spent'=>'site/spent',

                        'site/updateratings'=>'site/updateratings',

                        'site/keywords'=>'site/keywords',

                        'site/<siteLink:[a-zA-Z0-9-\.]+>/*'=>'site/show',

                        #'category/orderBy/<orderBy:\w+>/*'=>'categories/list',

                        'category/<alt:[a-zA-Z0-9-]+>/*'=>'categories/list',

                        #'category/*>'=>'categories/list',

                        //'home/*'=>'categories/list',

                        '/'=>'categories/list',

                        'orderby/<orderby:\w+>/*'=>'categories/list',

                        'currency/<currency:\w+>/*'=>'categories/list',

                        'search/orderby/<orderby:\w+>/*'=>'search/',

                        '<pageUrl:[a-zA-Z0-9-]+\.html>' => 'pages/StaticPage'

            )

	),

          	'user'=>array(

                        // enable cookie-based authentication

                        'allowAutoLogin'=>true,

            'loginUrl' => '/user/login',

                ),


        'cache'=>array(

                       	// enable cache

                        'class'=>'system.caching.CFileCache',

                ),


        'mailer' => array(

            'class' => 'application.extensions.mailer.EMailer',

            'pathViews' => 'application.views.email',

            'pathLayouts' => 'application.views.email.layouts'

                ),

/*	'clientScript'=>array(

                'packages'=>array(

                        'jquery'=>array(

                                'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.8.2/',

                                'js'=>array('jquery.min.js'),

                        )

                ),

                // other clientScript config

        ),


'clientScript' => array('scriptMap' => array('jquery.js' => false, 'jquery' => false))

*/

  	),


	// application-level parameters that can be accessed

        // using Yii::app()->params['paramName']

        'params'=>array(

                // this is used in contact page

                'adminEmail'=>'xxx@xxx.com',

                'rewardsEmail' => 'xxx@xxx.com',

                'CHtmlPurifierConfig' => array('HTML.AllowedElements'=>'p,strong,em,span,ul,li,ol,br'),

                'bitcoinRpcUrl' => ''

        ),

);