0

this is related to my previous question regarding [native J4 redirects][1]. I'm looking at a workaround but my previous question is still valid.

I'm using [Jbusiness][2] and where previously we could redirect old business listings to new listings using ReDJ the native Redirect plugin only redirects if a 404 header is found. As my client adds the redirects when required and is not tech savvy .htaccess redirects are not really a long-term solution.

When a listing is disabled, rather than show a 404 response header Jbusiness shows a 'Listing Disabled' page. I.E. [https://bit.ly/3q7KZSK][3] so redirects no longer work.

I've created an override of the default_inactive.php from JBusiness:

<?php
/**
 * @package    J-BusinessDirectory
 *
 * @author     CMSJunkie http://www.cmsjunkie.com/
 * @copyright  Copyright (C) 2007 - 2022 CMSJunkie. All rights reserved.
 * @license    https://www.gnu.org/licenses/agpl-3.0.en.html
 */ 
defined('_JEXEC') or die('Restricted access');
require_once 'header.php';
?>

<div class="item-inactive">
    <img src="<?php echo BD_PICTURES_PATH.'/item-disabled.svg' ?>">
    <div class="title"><?php echo isset($this->company->name) ? $this->escape($this->company->name) : "" ; ?></div>
    <p><?php echo JText::_("LNG_COMPANY_INACTIVE")?></p>
    <a class="btn btn-primary" href="<?php echo JBusinessUtil::getWebsiteURL(true) ?>"><i class="la la-arrow-left"></i> <?php echo JText::_('LNG_GO_TO_HOMEPAGE'); ?></a>
</div>

Then removed require_once 'header.php'; and replaced with

/*** Custom Error Page ***/
if ($this->error->getCode() == '404') {
header("HTTP/1.0 404 Not Found");
exit;
}

But receive a the error Call to a member function getCode() on null

As I'm sure you all know by now, I'm not a PHP person. I know after all these years I should really give myself a kick and get more involved with it.

I've logged a support ticket with CMS Junkie as well, I do feel this page should throw a 404 to be honest.

Kind Regards D [1]: Joomla 4.3.3 Imported Redirects not working [2]: https://www.cmsjunkie.com/joomla_business [3]: https://bit.ly/3q7KZSK

1 Answer 1

1

You need to throw an exception with 404 error code. This should work provided the component does not catch it.

throw new Exception(JText::_('LNG_COMPANY_INACTIVE'), 404);

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.