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. Jun 3, 2019 at 12:18
  • I added the attempts to de description. Jun 3, 2019 at 12:34
  • Have you tried to remove the URL from Google via Search Console/Webmaster Tools?
    – Irata
    Jun 3, 2019 at 23:17
  • @Irata thanks! Trying that now. Jun 4, 2019 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, 2019 at 7:15

2 Answers 2


Yeah, I get all the search engines crawling URLs that have never existed on the site. It happens a lot, typically because they have that URL handed to them by some random site on the web. You can't control for that, and none of the search engines care very much about it, so that's a losing battle.

Some SEF extensions, such as sh404SEF, can handle that URL as an alias for a legitimate page, so if it bugs you, that may be one approach.

You should be able be able to use .htaccess, but I wouldn't use the syntax you posted as an example of what you tried. Apache's Redirect tends to take a greedy approach, so that example would also redirect, for example, ?Itemid=101 as well as ?Itemid=.

A better pattern would be like:

RedirectMatch "(.*)\?Itemid=$" "/whereever"

It will redirect every url that ends with that, and mod_rewrite might even be better. But, as with all .htaccess tries, this depends on the server config allowing these directives.

My temptation might be to consider that an "attack", and 403 it, rather than redirecting it. It wouldn't be the first time folks with bad intentions fed their links to search engines to have them locate new prey.

  • Thanks for the edit, I'd forgotten about formatting the code.
    – Arlen
    Aug 8, 2019 at 13:57

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.

  • Unfortunately, most of the time it simply checks to see if Itemid is set, not whether it is set to a non-zero number. (try &Itemid=0 with the above, I get to the same page.) Oddly enough, negative numbers seem to 404, like they should, but zero seems to be a special case.
    – Arlen
    Aug 7, 2019 at 18:52

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.