Yii Url in SEO friendly format problem

Hi to everyone

I’m looking for a solution to transform the Yii url from the standard format

http://localhost/<nome_sito>/index.php?r=site/index

into a more SEO friendly format, like:

http://localhost/<nome_sito>/site/index

In config/main.php I’ve this




'urlManager'=>array(

            'urlFormat'=>'path',

            'showScriptName' => false,

            'rules'=>array(

     '<controller:\w+>/<id:\d+>'=>'<controller>/view',

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

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

       ),            

      ),



In protected/views/layouts/main.php I use this code to call the pages




 $this->widget('zii.widgets.CMenu',array(

			'items'=>array(

				array('label'=>'Home', 'url'=>array('/site/index')),

				array('label'=>'Ricerca','url'=>array('/site/ricerca')),

				array('label'=>'Servizi', 'url'=>array('/site/page', 'view'=>'about')),

				array('label'=>'Contatti', 'url'=>array('/site/contact')),

				//array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

				//array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

			),

		));



Now the actual problem is that when I try to go to some of those pages the link

the adress I got is this http://localhost/<nome_sito>/index.php/controlle/action

So I’ve modified the .htacces ( but I didn’t understand if I need to modify the htaccess in the yii folder or the one in my local server).




Options +FollowSymLinks

IndexIgnore */*

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



In this way I was able to overwrite the index.php in the adress, but when I click on one of the pages in the menu

above I got an apache error 404, that the page doesn’t exist on my local server.

There’s something that I need to change in my menu widget?

I need to use baseUrl to call the correct location of the pages?

Another thing when I see the website with index.php in the adress, I can’t see images.

Thanks in advace to everyone.

What if you write only below code and no rules and no htaccess.


'components'=>array(

			'urlManager'=>array(

				'urlFormat'=>'path',

				'showScriptName'=>false,

				),

		),

Thank you for your answer.

I tryed your solution but nothing change.

link now appear in this format

http://localhost/<site_name>/site/page/view/mydomains

and this is correct, but i recive the same 404 error of apache.

  1. Just check if you have mod_rewrite enabled.

  2. don’t write any htaccess code other than below.


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

Also have a look at http://www.yiiframework.com/forum/index.php/topic/30739-404-errors-on-apache2-ubuntu/page__view__findpost__p__148028

mod_rewrite is enabled in apache conf.

And also in the htaccess I have what u write.

But nothing change I recive always "object not found error 404".

I suspect that the problem is that I have my app in subfolder of the server folder.

I have the local server folder in /srv/http and my app in /srv/http/covado.

Try adding RewriteBase like this:


RewriteEngine on


RewriteBase /covado/


# 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