Here’s my setup:
config.php
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
'showScriptName'=>false,
),
.htaccess:
Options +FollowSymlinks
#+FollowSymLinks must be enabled for any rules to work, this is a security
#requirement of the rewrite engine. Normally it's enabled in the root and we
#shouldn't have to add it, but it doesn't hurt to do so.
RewriteEngine on
#Apache scans all incoming URL requests, checks for matches in our
#.htaccess file
#and rewrites those matching URLs to whatever we specify.
#allow blank referrers.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.dev [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?dev.site.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
# 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
On layout menus I have this:
$this->widget('zii.widgets.CMenu',
array('items'=>
array(
array(
'label'=>Yii::t('site','A'),
'url'=>array('/site/index')
),
array(
'label'=>Yii::t('site','Q'),
'url'=>array('rooms/index')
),
array(
'label'=>Yii::t('site','G'),
'url'=>array('gastronomy/index')
),
array(
'label'=>Yii::t('site','A'),
'url'=>array('activity/index')
),
array(
'label'=>Yii::t('site','S'),
'url'=>array('services/index')
),
array(
'label'=>Yii::t('site','C'),
'url'=>array('contacts/index')
),
array(
'label'=>Yii::t('site','R'),
'url'=>array('booking/index')
)
)
)
);
I explicit call index here, because it seems that, calling it explicitly is required.
With this setup, each time I click on those links I get, for example:
While I wish to get:
W/out the index name.
What am I missing here ?
There is difference between index entry file and default action. You’re messing those things.
If you make
'showScriptName'=>trueyou will see, that your links will be changed to something like/index.php/rooms/indexwhereindex.phpis the index entry file.As you see with option
'showScriptName'=>falseyou don’t have thatindex.phpin your links, that means that you successfully removed entry script from links.Now your
room/indexiscontroller/actionpart of URL route.roomis controller andindexis action.To see
http://site.dev/rooms/instead ofhttp://site.dev/rooms/indexyou have to edit your URL routes like that:Notice the line
'<controller:\w+>'=>'<controller>/index'i added. That makes default actionindexto createcontrollerroute instead ofcontroller/index.