I have some sections of my web in joomla that are accessed like this:


I want to transform in something like that:


replace the old name with the new one: com_component --> com_newname

It's possible? How can I do it?


I've tried to edit .htaccess file (mod rewrite) with:

RewriteCond %{QUERY_STRING} ^(.*)com_component(.*)$
RewriteRule ^(.*) $1?%1com_newname%2 [R=302,L]

but it does not work well... It shows url local too

Edited: I've tried to modify

    public function onAfterRoute()
    $app = JFactory::getApplication();
    $doc = JFactory::getDocument();

    if ($app->getName() != 'site' || $doc->getType() !== 'html')

    $router = $app::getRouter();

    $uri     = JUri::getInstance();
    $domain  = $this->params->get('domain');

    if ($domain === null || $domain === '')
        $domain = $uri->toString(array('scheme', 'host', 'port'));

    $link = $domain . JRoute::_('index.php?' . http_build_query($router->getVars()), false);

    if ($uri->toString() !== $link)
        $doc->addHeadLink(htmlspecialchars($link), 'canonical');

in: /plugins/system/sef/sef.php

  • Global Configuration >> Enable SEF URL's
    – Lodder
    Mar 9, 2018 at 11:53
  • Yes, I have it activated. But for this I think I need to edit the htaccess file with new rule to rewrite
    – Norak
    Mar 9, 2018 at 12:00

1 Answer 1


You can do this by overriding the router in the System plugin, either create a new system plugin or add a method in the already existing system plugin that is enabled on your site.

Create the following method

 * This event is triggered after the framework has loaded and initialised and the router has routed the client request.
 * @return void
function onAfterRoute() {
    $app = JFactory::getApplication();
    $input = $app->input;
    $option = $input->get('option', "");

    // will override on the following condition only
    if ($option == "com_component") {
        $input->set('option', "com_newname");

This will allow you to override all calls to your "com_component" to "com_newname".

You can also override view as per these.

More Info can be found here => https://docs.joomla.org/Plugin/Events/System

  • the code of the function "onAfterRoute()" in my joomla framework is different. I have tried to add the condition that you have told me but it gives me this error: "Content encoding error" and it doesn't let me enter the page :(
    – Norak
    Mar 12, 2018 at 15:10
  • Please provide your joomla version, also this method can be used in a system plugin only, can you provide the path of file you are adding the code to.
    – Pratyush
    Mar 13, 2018 at 8:43
  • My Joomla version is 3.4.6. I have edited the question with the code of this function. Thanks for your help!
    – Norak
    Mar 13, 2018 at 8:49
  • Was this method triggered, and if it is and still you are not able to set the new component, try to make changes in the application input $app = JFactory::getApplication(); $input = $app->input; as in my example as the option in the input will be used to create the new link
    – Pratyush
    Mar 14, 2018 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.