I wish to get for all index default actions the folowing URL:
http://www.site.com/controller/
Instead of the actual:
http://www.site.com/controller/index
Here’s the code on the MENU (notice I DO have the index written. Because (I believe) it’s the proper way for doing so.
$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')
)
)
)
);
My .htaccess file placed on public_html looks like the following:
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
Finally, the URL manager that I now have:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>'=>'<controller>/index',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
'showScriptName'=>false,
),
I’m still getting that annoying index appearing on the URL. How can we properly hide it ?