Page handler works on localhost but gives 404 when online

Description of issue or problem I’m having:
I have a generic plugin with a series of custom template files, handled by a page handler that checks the URL and assigns the appropriate .tpl file for the page. When I visit any of the URLs on my localhost dev server it works fine every time.

When I upload the plugin to my online dev’ server and attempt to view the page(s), the server returns a 404 and there is no supporting information in the logs other than the 404 itself.

I’m struggling to find out why it’s not working online and was hoping someone could give me some advice.

Steps I took leading up to the issue:
The setPageHandler function is as follows:

public function setPageHandler($hookName, $params) {
		$page = $params[0];
		if ($page === 'clinical-queries') {
			$this->import('RCVSKClinicalQueriesPluginHandler');
			define('HANDLER_CLASS', 'RCVSKClinicalQueriesPluginHandler');
			return true;
		}
		if ($page === 'clinical-queries-submit') {
			$this->import('RCVSKClinicalQueriesSubmitPluginHandler');
			define('HANDLER_CLASS', 'RCVSKClinicalQueriesSubmitPluginHandler');
			return true;
		}
		return false;
	}

The plugin handler class is as follows:

import('classes.handler.Handler');
class RCVSKClinicalQueriesPluginHandler extends Handler {
	public function index(array $args, Request $request):string {
		$plugin = PluginRegistry::getPlugin('generic', 'rcvskclinicalqueriesplugin');
    $templateMgr = TemplateManager::getManager($request);
    return $templateMgr->display($plugin->getTemplateResource('frontend/pages/clinicalqueries.tpl'));
  }

  public function view($args, $request):string {
		$plugin = PluginRegistry::getPlugin('generic', 'rcvskclinicalqueriesplugin');
    $templateMgr = TemplateManager::getManager($request);
    return $templateMgr->display($plugin->getTemplateResource('frontend/pages/clinicalqueries.tpl'));
  }
}

and the other handler is:

import('classes.handler.Handler');
class RCVSKClinicalQueriesSubmitPluginHandler extends Handler {
	public function index(array $args, Request $request): string {
   // print_r($_POST);
		$plugin = PluginRegistry::getPlugin('generic', 'rcvskclinicalqueriesplugin');
    $templateMgr = TemplateManager::getManager($request);
    return $templateMgr->display($plugin->getTemplateResource('frontend/pages/clinicalqueriessubmit.tpl'));
  }

  public function view($args, $request) {
		$plugin = PluginRegistry::getPlugin('generic', 'rcvskclinicalqueriesplugin');
    $templateMgr = TemplateManager::getManager($request);
    return $templateMgr->display($plugin->getTemplateResource('frontend/pages/clinicalqueriessubmit.tpl'));
  }
}

What I tried to resolve the issue:
I have been checking my code and looking through the forums but can’t really see why it works locally but not online.

Application Version - e.g., OJS 3.1.2:
OJS 3.3.0.10 (the online server has just been updated to 3.3.0.11, everything else works. Note that this issue existed before the upgrade too.)

Additional information, such as screenshots and error log messages if applicable:
I checked the “versions” table in the database and there exists an entry on both the localhost and online databases for the plugin.

The 404 page itself is not what I would call a typical OJS 404 page. There is no stack trace, just the 404 itself, and in the error logs :-

[Tue Jun 14 10:04:27.663977 2022] [php7:notice] [pid 62215] [client 92.13.214.246:63857] ojs2: 404 Not Found

Does anyone have any ideas why it’s not working?

This one is still haunting me. The plugin works 100% on my locahost but online it shows a 404 page not found error, and I have no idea why.

There is no indication in the server logs why it is not working, just the reference to the 404 error in the logs with no stack trace, nothing else.

Does anyone know of any reason that this may be not working? Could it be something in config.inc.php perhaps?

Hi @Ant_Forshaw,

How was the plugin installed into the system? If it was installed via the Plugin Gallery or the “upload a plugin” tool in OJS/OMP/OPS, then it’ll be registered with the system. If not (i.e. if you placed the plugin files into the filesystem directly) it may not be correctly registered, and you might see behaviour like hooks not being called when expected. If that’s the case, you can use a command-line tool to register the plugin:

php lib/pkp/tools/installPluginVersion.php path/to/plugin/version.xml

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks @asmecher I tried that command but it didn’t appear to fix anything. I cleared all caches but still the plugins list doesn’t display, no errors in the console but the same error in the log file.

I will uninstall the plugin and reinstall it and try again. Still scratching my head on this one.

Quick update to this one - There was an additional page handler in my plugin directory (making 2 page handlers). Deleting one of them caused the plugins page to load again, so I refactored the plugin code to use a single page handler and that has allowed me to proceed.