routing in Joomla 2.5

1,262 views
Skip to first unread message

FRamonTB

unread,
Sep 11, 2012, 12:47:49 PM9/11/12
to joomla-de...@googlegroups.com
Hello all,

   I have coded a router.php that build a SEF URI from this: 

   www.mysite/index.php?option=myComp&controller=myContr&id=25

to this:
 
   www.mysite/index.php/component/myComp/item-number-25

But I would like to get a route like this:

   www.mysite/item-number-25

How could I achieve this coded in myCompBuildRoute() function?

I have tryed with:

   unset($query['option']);

but I get a SEF URI like this:

   www.mysite/index.php/component/item-number-25

I can't either to make the "component" segment disappear, nor the "index.php". How could I do?

Thanks in advance. 
Regards: framontb

FRamonTB

unread,
Sep 11, 2012, 1:26:26 PM9/11/12
to joomla-de...@googlegroups.com
OK... after enabling the Use Apache mod_rewrite/URL rewriting option and Save, only remains the "component" segment:

www.mysite/component/item-number-25

I want to delete it from the URI. 

Any help will be appreciated.

Regards

fornandakishore

unread,
Sep 11, 2012, 8:16:25 PM9/11/12
to joomla-de...@googlegroups.com
Create a menu item for that link, then only the component word will gone. i.e. you have created a menu item with alias name as 'item-number-25' then the url should be www.sitename.com/item-number29
 
Thanks & Regards

Nanda Kishore. M

Senior PHP Developer

http://php-desk.blogspot.com

Mobile: + 91 98499 71144 




--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/PEFiKgaDC1MJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

FRamonTB

unread,
Sep 12, 2012, 10:31:31 AM9/12/12
to joomla-de...@googlegroups.com
Thanks for the response Nanda !!!

Are there a way for suppressing the word "component" in the SEF URI without creating a menu item? Perhaps something that I can do inside my router.php file of my component?

Regards: framontb
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

FRamonTB

unread,
Sep 12, 2012, 12:44:49 PM9/12/12
to joomla-de...@googlegroups.com

Hello,

   finally I found a way for suppressing the word "component" when there is no "option" in the URI segments. What I'm going to say probably is a    folly but I would like to know why...

   I have modified the function _buildSefRoute(&$uri) inside the class JRouterSite (includes/router.php) so that the code:

if (!$built) {
$tmp = 'component/'.substr($query['option'], 4).'/'.$tmp;
}

   changed to be:

if (!$built) {
if (isset($query['option'])) $tmp = 'component/'.substr($query['option'], 4).'/'.$tmp;
}

so if there is no "option" (by means of a "unset( $query['option'] );" inside my component router.php) there will not be "component" segment... the point is: why I need the "component" word, if I have no "option"? have I broken some functionality? I don't understand very well the insides of the routing process, so I don't know if this little change have broken something.

I know... it is not advisable to change the Joomla! core. The same can be achieved by an external RewriteRule with the mod_rewrite module inside apache, but such thing will decrease performance server.

Regards: framontb

Adam Stephen Docherty

unread,
Sep 14, 2012, 12:23:57 AM9/14/12
to joomla-de...@googlegroups.com
>>> I don't understand very well the insides of the routing process, so I don't know if this little change have broken something.

Join the club... does anyone know of any updated information / docs on using JRoute in the new versions, ie 2.5? 

Matt Thomas

unread,
Sep 14, 2012, 7:00:38 AM9/14/12
to joomla-de...@googlegroups.com

Hi framontb,

I'm not any sort of expert, but I don't see any good reason for hard coding part of the URL. I'd like to encourage you to create a pull request, with this change, to see if this can fixed in core.

Thanks for reporting your fix.

Best,

Matt Thomas
Founder betweenbrain™
Lead Developer Construct Template Development Framework
Phone: 203.632.9322
Twitter: @betweenbrain
Github: https://github.com/betweenbrain

Composed and delivered courtesy of Nexus 7.

To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/F78j7eujiBEJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.

elin

unread,
Sep 14, 2012, 8:37:08 AM9/14/12
to joomla-de...@googlegroups.com
What if someone made a menu link  with the alias item-number-25?

I'm assuming that you mean item-number- woudl be replaced by an alias since obviously  autogenerating item-number-25 from the id and nothing else you would have a mega problem  if two components did the same thing?

Elin
To unsubscribe from this group, send email to joomla-dev-general+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

FRamonTB

unread,
Sep 14, 2012, 11:04:33 AM9/14/12
to joomla-de...@googlegroups.com
Hello all,

   thanks for your kind responses. 

    I think Elin is right in all that she said. Please, let me explain myself a little more about the problem I'm involved with, so you could understand this estrange things I'm proposing. Please, take it carefully because I'm not very expertise (nor much, nor little) in the subject.
  All of these is regarding SEO, since a site-administrator's perspective. Suppose I have a data base with thousand of items (say cars for example). So, I can't generate a menu item for each of the items. I want in my site an URI with only relevant words for the item view specifically (nor other views, that I want process as the normal router treatment). AFAIK, this is better for SEO. For example, the word "component" is not relevant for search engines; neither the name of my component... so I want these words out of the URI. Right?
   I have an easy way to do this... Simply writing the URI directly without using JRoute::_ function. So, I can have an URI of the type described:
www.mysite/item-number-25
   Suppose that the number "25" could be any in the range  (1, 20.000). Now Joomla! have a problem, because it doesn't know how to parse this query: "item-number-25". For solving this problem I can put an "internal" RewriteRule inside the .htaccess file provided by joomla! 2.5, and indicate here what the component router should it use. The problem with these is that now the component is not ready for use after install and need some configuration work. Besides, there are two different ways to process the URIs (with JRoute, and without), wich is not nice. So, I would like to generate the 'simple' URI since the router component.
   For so speaking there are two problems:
- I can't generate the simple URI: www.mysite/item-number-25 inside my router component, without touching the core.
- I can't say the Joomla routing process how to process it, without touching the core.

   And this is the problem I'm trying to solve...
   Please, let me apologize , because I explain myself bad and besides, probably I said wrong things and too long. I would appreciate someone that open my eyes. Don't doubt to say "folly" if this is this the case !!!

Regads: framontb

elin

unread,
Sep 14, 2012, 11:31:25 AM9/14/12
to joomla-de...@googlegroups.com
As a webmaster all you need to do is make a menu link for each category root in each extension (not the real category root), that will clean up everything. It won't be pretty if you have deep categories but it will work to get rid of the component segment.

Elin

Nick Weavers

unread,
Sep 14, 2012, 8:59:06 PM9/14/12
to joomla-de...@googlegroups.com
Hi  framontb,

I had a similar requirement.

My clients SEO company wanted to publish lots of topical content relevant to the clients industry (mortgages) with chosen keywords appearing in the urls, and for links to those articles to appear at the bottom of the home page. When a link was clicked, the article was to be show alongside a "call to action" form and other content.   

I managed to get things to function as I wanted for SEO as follows:

1) My component pretty much controls the whole site including the front page, so I created a menu item with a title of Home Page and a link of the type external URL type and gave it the URL of my component and the view for the homepage (eg index.php?option=com_dealdirect&view=homepage).
2) I clicked the radio button for 'yes' on the Default Page option to make this menu item get actioned when the site is visited via a URL with no query or path appended to the domain name.
3) Now, since my component is running my home page, my custom router gets a chance to parse and build my URL's. That means I can pretty much have any url my router can build and parse.
4) Also, any module I write that is shown on the site template while my component is in control can also create links that the component router will parse.

So, if the front page of your site was a catalogue listing generated by your component, you could create the links in the format you want  (/item-number-25) and your components ParseRoute function could decode this to build a query string like task=itemController.showItem&item=25 to show a full page of info for the item.

You can see it in action on the site at www.dealdirectfinancial.co.uk.

Nick 

      



    Reply all
    Reply to author
    Forward
    0 new messages