URL without controller name

Hello everybody!

I have a small question…

How to make URL without controller name?

Is it possible?

For example: I need this type of URL => http://domain.ru/page.html

[color="#FF0000"]instead of[/color] http://domain.ru/controller/page.html

Could you help me, collegues?


p.s. I am sorry for my English…

  1. You have to hide the index.php

    • Url Management (6.)

    • see wiki hide index php

  2. Check the possibilities/rules of the Url Management

to Joblo

thaks a lot for your tips!

But I have already done URL without index file…

Now I need to get rid of the controller name.

I will follow your links

Something like this could works:


'urlManager' => array (

    'urlFormat' => 'path',

    'caseSensitive' => true,

    'showScriptName' => false,

    'urlSuffix'=>'.html',

    'useStrictParsing'=>true,

    'rules'=>array(

        array('controller/page', 'pattern'=>'page', 'urlSuffix'=>'', 'caseSensitive'=>false),

        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',

    )

),

[color=#008800]Just Check Code[/color][color=#008800]

[/color][color=#008800]‘urlManager’[/color][color=#000000] [/color][color=#666600]=>[/color][color=#000000] array [/color][color=#666600]([/color][color=#000000]

[/color][color=#008800]'urlFormat'[/color][color=#000000] [/color][color=#666600]=&gt;[/color][color=#000000] [/color][color=#008800]'path'[/color][color=#666600],[/color][color=#000000]


[/color][color=#008800]'caseSensitive'[/color][color=#000000] [/color][color=#666600]=&gt;[/color][color=#000000] [/color][color=#000088]true[/color][color=#666600],[/color][color=#000000]


[/color][color=#008800]'showScriptName'[/color][color=#000000] [/color][color=#666600]=&gt;[/color][color=#000000] [/color][color=#000088]false[/color][color=#666600],[/color][color=#000000]


[/color][color=#008800]'urlSuffix'[/color][color=#666600]=&gt;[/color][color=#008800]'.html'[/color][color=#666600],[/color][color=#000000]


[/color][color=#008800]'useStrictParsing'[/color][color=#666600]=&gt;[/color][color=#000088]true[/color][color=#666600],[/color][color=#000000]


[/color][color=#008800]'rules'[/color][color=#666600]=&gt;[/color][color=#000000]array[/color][color=#666600]([/color][color=#000000]


    array[/color][color=#666600]([/color][color=#008800]'controller/page'[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'pattern'[/color][color=#666600]=&gt;[/color][color=#008800]'page'[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'urlSuffix'[/color][color=#666600]=&gt;[/color][color=#008800]''[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]'caseSensitive'[/color][color=#666600]=&gt;[/color][color=#000088]false[/color][color=#666600]),[/color][color=#000000]


    [/color][color=#008800]'&lt;controller:&#092;w+&gt;/&lt;action:&#092;w+&gt;'[/color][color=#000000] [/color][color=#666600]=&gt;[/color][color=#000000] [/color][color=#008800]'&lt;controller&gt;/&lt;action&gt;'[/color][color=#666600],[/color][color=#000000]


[/color][color=#666600])[/color][color=#000000]

[/color][color=#666600]),[/color]

to Ivica and shailesh

I have just tried your code - didn’t help…

I have got such server response =




Unable to resolve the request "".

The requested URL was not found on this server. 

If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster. 



The string = ‘useStrictParsing’=>true = has caused this server response

If you only have one controller, named site it this example, you could use:


'<action:[\w\-]+>.html' => 'site/<action>',

I am sorry, guys… I am confused…

Here is my config file code =




return array(

 'name'=>'Paul New Project',

 'defaultController'=>'paul',

 'components'=>array(

   'urlManager'=>array(

     'urlFormat'=>'path',

     'caseSensitive' =>true,

     'showScriptName'=>false,

     'urlSuffix'=>'.html',

     //'useStrictParsing'=>true,

     'rules'=>array(

       '<action:[\w\-]+>.html' => 'site/<action>',

     ),

   ),

  ),

);



Where is my mistake?

Change:


'<action:[\w\-]+>.html' => 'site/<action>',

to:


'<action:[\w\-]+>.html' => 'paul/<action>',

Oh, and I haven’t defined a urlSuffix.

to Splendid

Das ist fantastisch! = It’s excellent!

[color="#FF0000"]Many times -> thanks a lot to you![/color]

It work!


'<action:[\w\-]+>' => 'paul/<action>'

tell me please, Splendid: on the right - part of URL and on the left - pattern?

Am I right?

I’m fairly new to Yii myself but this is how I see it. The left part is the url pattern, right side is the path of scripts. So the string before the slash is the controller, the part after the slash the view. With above code we switch those.

to Splendid

Once more - thank you very much!

Thank You Splendid,

It worked for me.

I have added like this

‘<action:[\w\-]+>’=>‘page/about’,

and it works for me… :)