Search code examples
phpyiiyii-url-manager

Hide Default Controller name From Url that have Arguments - Yii


I use path-format of yii urls... I want change this url

mypage.com/site/profile/username/name

to

mypage.com/profile/username/name

{site: defaultControler, profile: an Action, username: Argument, name: Argument's value }

how can this done by urlManager in yii?


Solution

  • This should work for you. Add this rule /profile/* into your config.php in components urlManager part. Params like "username" should be forwarded automatically by Yii.

        'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName' => false,
            'rules'=>array(
                '/profile/*' => array('/site/profile/'),
            ),
        ),
    

    Also check your .htaccess and allow Rewrite.

    Options +FollowSymlinks
    RewriteEngine on
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # otherwise forward it to index.php
    RewriteRule . index.php