Joomla BuildRule adds language code at the back of setPath

by Mike Feng   Last Updated March 12, 2018 21:10 PM

I'm having a problem with building the rule for a particular URL. Here's what I have in my system plugin:

function onAfterInitialise() {
    require_once '/path/to/myhelper.php';
    $router = $this->app->getRouter();
    $router->attachBuildRule(array('MyHelper', 'BuildRoute'));
    $router->attachParseRule(array('MyHelper', 'ParseRoute'));

In the myhelper.php:

class MyHelper {
     public static function buildRoute(&$router, &$uri) {

In another file, when I try to JRoute any url, it adds the language code at the end instead of the beginning. For example:

echo JRoute::_('helloworld.php');
//this will print "/foobar/en/" instead of just "/en/foobar/" or possibly just "/foobar"

A few things:

  1. I have the Joomla system plugin System - Language Filter enabled.

  2. Setting Remove URL Language Code to either Yes or No does not change the outcome.

  3. Disabling the plugin will remove the language code, but I can't do that.

  4. The baffling part is, all other Joomla generated URLs (like the ones in the menu), have the language code in front. eg

Any direction on this is greatly appreciated. Thanks in advance!

Related Questions

Generating URL in CLI

Updated April 13, 2018 11:10 AM

How to check if Joomla path is routable

Updated June 07, 2017 18:10 PM

Develop a System Plugin with Sample Data for Options

Updated January 06, 2019 18:10 PM

How to remove rel="nofollow" with Joomla Buffer?

Updated May 28, 2017 04:10 AM