Reputation: 2136
I wrote a custom non-mvc component (because i don't know how to make mvc component and now it's grown is size so changing it will take more time which is not possible for me) 'com_group' for my client.
Everything is fine but when it comes to sef urls it gives me urls like mysite/component/group/home
and in non sef urls like mysite/index.php?option=com_group&view=home
but client wants to remove component word from urls.
I also made a router for my component which remove every parameter correctly but it does not remove component. I also made a menu item for it but it didn't helped me.
Here is my router.php
<?php //error_reporting(E_ALL);
defined ( '_JEXEC' ) or die ();
jimport('joomla.error.profiler');
function GroupBuildRoute(&$query){
$segments = array();
//$query['Itemid'] = 201;
if( isset($query['view']) )
{
$segments[] = $query['view'];
unset( $query['view'] );
};
if( isset($query['pin']) )
{
$segments[] = $query['pin'];
unset( $query['pin'] );
};
return $segments;
}
function GroupParseRoute($segments){
$vars = array();
$app =& JFactory::getApplication();
$menu =& $app->getMenu();
$item =& $menu->getActive();
$items = $menu->getItems('component', 'com_group');
if (!isset($query['Itemid']))
$query['Itemid'] = 180;//$items->id;
// Count segments
$count = count( $segments );
//Handle View and Identifier
switch( $segments['0'] ){
case 'group_page':
$vars['view'] = 'group-pages';
break;
case 'group':
$vars['view'] = 'home';
break;
case 'folow':
$vars['view'] = 'follow';
break;
case 'start':
$vars['view'] = 'start-group';
break;
case 'group_eventplan':
$vars['view'] = 'group-event-plan';
break;
case 'group_member':
$vars['view'] = 'group-members';
break;
case 'manage_subscription':
$vars['view'] = 'manage-subscription';
break;
case 'group_msg':
$vars['view'] = 'group-message';
break;
case 'group_invite':
$vars['view'] = 'invite-friends';
break;
case 'other_group':
$vars['view'] = 'other-groups';
break;
case 'groupinfo':
$vars['view'] = 'group-info';
break;
case 'home':
$vars['view'] = 'group-home';
break;
}
if (!isset($item)) {
$vars['view'] = $segments[0];
$vars['pin'] = $segments[1];
return $vars;
}
if($count==2){
$vars['view'] = $vars['view'];
$vars['pin'] = $segments[1];
return $vars;
}
return $vars;
}
I also want to replace group_msg
to group-message
also so that new urls should be component/group/group-message/
not component/group/group_msg
I tried Remove component part from sef url, menu item not completely but didn't helped me.
Upvotes: 1
Views: 1743
Reputation: 2136
Finally i managed to solve the question by myself. I am mentioning steps taken to help others. (Please write me if you want source code to use it with your project)
Step 1: add a menu item (Joomla Administrator -> Menus ->Menu Manager->Add new Item)
Step 2: The newly added menu item will be provided an id, add this id to all urls of your component like this.
index.php?option=com_your_component_name&Itemid=newly_generated_id
that's it.
Upvotes: 1
Reputation: 25485
The first option I would try is sh404SEF
Good luck!
EDIT
If SEF extensions are not an option for you, perhaps using .htaccess and redirect, something like the following :
RewriteEngine On
Redirect /component/group/home /something-else
Upvotes: 0