Google has indexed an URL on my site like this: https://www.joomla.org/?Itemid=

This results in strange page of course. Try it with your own site!

What would be the best way to redirect this to the Joomla default menu item?

Because Joomla's Redirect Manager did not work and a 301 in the htaccess neither...

My solution is this:

// Joomla System Trigger
public function onAfterRoute()
    // some basic checks
    if ($this->app->isSite() === false) return; 

    $app = JFactory::getApplication();
    $Itemid   = $app->input->getInt('Itemid');      

    // if an Itemid exists return
    if ($Itemid) return true;

    // get the default menu item id
    $menu = JFactory::getApplication()->getMenu();
    $menu_default = $menu->getDefault();
    $menu_default_id = $menu_default->id;

    // route it
    $link = 'index.php?Itemid=' . $menu_default_id;
    $link = JRoute::_($link);       

    // redirect to it
    $app->redirect($link, 'We had an empty Itemid.');

But could / should this be handled differently?

The other methods I tried were as follows:


Redirect 301 /?Itemid= https://www.joomla.org/

And via the Redirect Manager:

Redirect Manager

The <jdoc:include type="component" /> is empty (of course). That is what I meant by strange. That's why I want it to redirect to the default menu item.

Btw. Google indexed the page (only) with the Google Links. e.g. Google Nieuws

See image.Google Nieuws

It's not in my sitemap, not anywhere in the code / database. Screaming Frog SEO spidered it completely.

But ok, I asked Google to remove the URL. We'll see.

  • The two techniques that didn't work seem like wise choices. Perhaps show us your attempts to implement those techniques -- maybe we can sort you out. – mickmackusa Jun 3 at 12:18
  • I added the attempts to de description. – COBIZ webdevelopment Jun 3 at 12:34
  • Have you tried to remove the URL from Google via Search Console/Webmaster Tools? – Irata Jun 3 at 23:17
  • @Irata thanks! Trying that now. – COBIZ webdevelopment Jun 4 at 6:42
  • @COBIZwebdevelopment in your post you say "The result is a strange page of course". What is the result you are seeing that is strange or can you provide a link to the page? I have tried on my some of my own sites, including a localhost site, and some just display the Home page of the site with the www.mydomain/?Itemid= in the URL but I have now found some that do get mangled. I tested the example you provided with joomla.org/?Itemid= and I get the home page but pretty much nothing in the main block/container is displayed. Is that what you are seeing? – Irata Jun 4 at 7:15

I have been able to recreate the issue on more of my sites and I think that you should report the issue as a Bug to the Joomla team to address rather than trying to create your own work around.

I don't profess to understand the details of what is going in here but the code in ../libraries/src/Router/ spends a lot of effort encoding, decoding and validating URI's so I think that someone who understands it could/should create a rule or check to handle an empty Itemid= on an incoming or outgoing URL.

Unless you can identify the code creating the empty Itemid= that Google is indexing I think this would be the best way to fix the issue for everyone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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