Skip to content

Instantly share code, notes, and snippets.

@phproberto
Created October 27, 2017 11:54
Show Gist options
  • Save phproberto/2127fa2a687751b425aa3b2784b62823 to your computer and use it in GitHub Desktop.
Save phproberto/2127fa2a687751b425aa3b2784b62823 to your computer and use it in GitHub Desktop.
Dummy router for Jooma Blank Component causing no 404 pages

Reproduce the issue:

  • You have Blank Component assigned to the home page of your Joomla! site.
  • When you manually enter a wrong url you don't get any 404 error. Your site redirects all the non-existing urls to the home page.

Explanation

Joomla redirects all the non-existing urls to the router of the component assigned as home page. Blank component does not have a router so you just get redirected to the home page.

This is a dummy empty router that will force an empty option be set if the component router is called to parse any url. This should not break anything because Blank Component cannot work without a menu item assigned to it. It only ensures that the router does not parse any url.

Instructions

Copy the router.php file into your site /components/com_blankcomponent folder.

<?php
/**
* @package BlankComponent.Frontend
* @subpackage Router
*
* @copyright Copyright (C) 2017 Roberto Segura López. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('_JEXEC') or die;
/**
* Routing class from com_blankccomponent
*
* @since 3.0.1
*/
class BlankComponentRouter extends JComponentRouterBase
{
/**
* Build the route for the com_reditem component
*
* @param array $query An array of URL arguments
*
* @return array The URL arguments to use to assemble the subsequent URL.
*/
public function build(&$query)
{
return array();
}
/**
* Parse the segments of a URL.
*
* @param array $segments The segments of the URL to parse.
*
* @return array The URL attributes to be used by the application.
*/
public function parse(&$segments)
{
return array('option' => null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment