Yii Framework Forum: Yii Url in SEO friendly format problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Url in SEO friendly format problem Rate Topic: -----

#1 User is offline   corvallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 22-October 11

Posted 18 July 2012 - 07:51 AM

Hi to everyone
I'm looking for a solution to transform the Yii url from the standard format

http://localhost/<no...hp?r=site/index

into a more SEO friendly format, like:
http://localhost/<no...ito>/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/<no...ontrolle/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.
0

#2 User is offline   vibhaJadwani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 13-June 12
  • Location:India

Posted 18 July 2012 - 08:06 AM

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

'components'=>array(
			'urlManager'=>array(
				'urlFormat'=>'path',
				'showScriptName'=>false,
				),
		),

0

#3 User is offline   corvallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 22-October 11

Posted 18 July 2012 - 08:17 AM

Thank you for your answer.
I tryed your solution but nothing change.
link now appear in this format
http://localhost/<si.../view/mydomains
and this is correct, but i recive the same 404 error of apache.
0

#4 User is offline   vibhaJadwani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 13-June 12
  • Location:India

Posted 18 July 2012 - 08:50 AM

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.yiiframew...post__p__148028
0

#5 User is offline   corvallo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 22-October 11

Posted 18 July 2012 - 09:10 AM

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.
0

#6 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 312
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 20 July 2012 - 04:00 PM

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

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users