3

How can I remove the view name from a Joomla 2.5 URL? I am using this code in my BuildRoute method in router.php file but I'm not able to remove view name:

  if(isset($query['view'])){
    $segments[] = $query['view'];
    unset($query['view']);
}

and how can I remove component/mycomponent from the URL. My URL is now like this:

http://example.com/index.php/component/mycomponent/myview/id-itemtitle.html
itoctopus
  • 4,133
  • 4
  • 32
  • 44
saber
  • 336
  • 5
  • 15
  • Make a menu link. I always make a menu link to the item or to the top level category. You don't have to display this, make a separate menu to manage these. – Elin Mar 08 '14 at 12:45
  • Thank you I know with make menu don't show view name and component name but this part of my component not has menu i want remove view name and component/mycomponent without menu – saber Mar 08 '14 at 14:04
  • You need to make a menu link somewhere up the category hierarchy. Here is the issue. You could have many components containing rows of data, and then you could make an alias called item for any one of them. So if you have mydomain.com/item.html which one would it be? The menu system ensures that each url is unique. In the url component is a reserved word and each component name must be unique and each view name in a component must be unique. Assuming you are managing aliases correctly this ensures a unique url when there is no menu. – Elin Mar 08 '14 at 14:09
  • I have a view category and show many item in this view and when clik an one item go to item view by this url: mydomain.com/component/mycomponent/myview/id-itemtitle.html and now i want change my item url to this mydomain.com/id-itemtitle.html – saber Mar 08 '14 at 14:55
  • @saber please read Elin's answer again, there are so many posts here on stackoverflow regarding this same issue, you NEED to create a menu and if you want your component part of the url to start off the root of the site you might want to make that menu link your homepag – Riccardo Zorn Mar 08 '14 at 15:27
  • @Riccardo Zorn tank you. I read Elin's answer and say can't create menu for my items. but i am using id and title for show each item and item id is unique in url. my item has not alias and use id for them. – saber Mar 08 '14 at 16:55
  • You do not need to create a menu link for every item, just for the category or some category above it in the same branch. – Elin Mar 08 '14 at 17:28
  • Because each component has its own primary key they cannot be assumed to be unique. You may want to use a sef component that will lett you make custom urls. – Elin Mar 08 '14 at 17:29
  • yes Elin when click items in category view and go to item view don't show component name but show view name and another problem is: when click item link in my custom module show component name and view name in my item view url. I'm using this code for item link in my module `JRoute::_("index.php?option=com_mycomponent&view=myview&id=$id");` – saber Mar 08 '14 at 21:39

1 Answers1

0

You should create a menu item pointing to a specific view in your component to remove the view name and component... from your URL.

itoctopus
  • 4,133
  • 4
  • 32
  • 44