404 Error Page - Question | JoomShaper

404 Error Page

JH

Jeff Honeyager

Helix Framework 1 week ago

I want to create a custom 404 error page.

The existing one is very user unfriendly.

I have created an article in the uncategorized category and created a menu item to in on a "hidden menu."

How do I have Helix use that page / menu item instead of the existing 404 code?

Thanks.

0
8 Answers
JH
Jeff Honeyager
Accepted Answer
1 week ago #220221

Solution:

I asked Grok "Below is the Joomla version 6.0.3 error.php file from Helix Ultimate template to handle errors. Please modify it so that if a 404 error is generated, the system automatically redirects to the menu item: index.php?option=com_content&view=article&id=103"

It gave me the code. I edited error.php and placed the code into the file. It worked.

Grok responded:

Insert the redirect logic right after the initial defined('_JEXEC') or die(); line and before any output (e.g., before the <html> tag or heavy processing). This ensures the redirect happens early.

Here is the code:

// === ADD THIS BLOCK FOR 404 REDIRECT ===

if (isset($this->error) && $this->error->getCode() == 404) {

// Option 1: Simple redirect using the raw query string (works reliably)

header('Location: ' . JUri::root() . 'index.php?option=com_content&view=article&id=103', true, 302);
exit;

// Option 2: Use JRoute for cleaner/SEF-friendly URL (recommended if SEF is enabled)
// JLoader::import('joomla.application.component.helper');
// $url = JRoute::_('index.php?option=com_content&view=article&id=103', false);
// header('Location: ' . JUri::root() . ltrim($url, '/'), true, 302);
// exit;

}

// === END OF REDIRECT BLOCK ===

0
Paul Frankowski
Paul Frankowski
Accepted Answer
Senior Staff 1 week ago #220153

Hi Jeff,

It's NOT simple process.

  1. Read > https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder
  2. Or install extension that allows that withput codd customization.
  3. Or publish module inside position: 404 that will redirect to custom menu item
  4. Or customize error .php file from template folder
0
JH
Jeff Honeyager
Accepted Answer
1 week ago #220158

I read and tried the blog reference.

"Now, add the following code at the beginning of the file." >>> does not work.

Is it Joomla/Helix version dependent?

Why-Oh-Why can't you just change the template settings:

Template Styles >> shaper_helixultimate - Default >> Template Options >> Basic >> Error Page - then have a slector to choose a menu item - then select the menu from a list - or just add the menu item url. The coding would be minimal. I then truly becomes a simple process.

0
Paul Frankowski
Paul Frankowski
Accepted Answer
Senior Staff 1 week ago #220160

Don't blame me, I wanted/asked that feature a long time ago. But it's still on the wish-list :/

In my projects, in most cases, I use 404 position to add extra module inside (menu or different one).

Just focus to remove all broken links on your site, and 404 page will be "not needed" ;p

0
JH
Jeff Honeyager
Accepted Answer
1 week ago #220164

I'm rebuilding a crap site in raw html - and added a ton of content - removing broken links is not an option.

Have you looked at the new helix template's error.php. It is not the same as the one in: https://www.joomshaper.com/blog/create-a-custom-joomla-404-page-with-sp-page-builder

Can you pass this off to someone else?

0
JH
Jeff Honeyager
Accepted Answer
1 week ago #220165

I do use RSSEO from RSJoomla - it does a great job - if I can't get a custom 404 page working, I'll have to use redirects.

0
Paul Frankowski
Paul Frankowski
Accepted Answer
Senior Staff 1 week ago #220210

I will try to ask our developer STRONGER about that simple redirect feature. Too many people ask for that.

RSSEO is paid component, so this is not the perfect way for common user.

0
JH
Jeff Honeyager
Accepted Answer
1 week ago #220222

Solution:

I asked Grok "Below is the Joomla version 6.0.3 error.php file from Helix Ultimate template to handle errors. Please modify it so that if a 404 error is generated, the system automatically redirects to the menu item: index.php?option=com_content&view=article&id=103"

Then pasted the .php code into the prompt

It gave me the code. I edited error.php and placed the code into the file. It worked.

Grok responded:

Insert the redirect logic right after the initial defined('_JEXEC') or die(); line and before any output (e.g., before the <html> tag or heavy processing). This ensures the redirect happens early.

I used Option 1...

Here is the code:

// === ADD THIS BLOCK FOR 404 REDIRECT ===

if (isset($this->error) && $this->error->getCode() == 404) {

// Option 1: Simple redirect using the raw query string (works reliably)

header('Location: ' . JUri::root() . 'index.php?option=com_content&view=article&id=103', true, 302); exit;

// Option 2: Use JRoute for cleaner/SEF-friendly URL (recommended if SEF is enabled) // JLoader::import('joomla.application.component.helper'); // $url = JRoute::_('index.php?option=com_content&view=article&id=103', false); // header('Location: ' . JUri::root() . ltrim($url, '/'), true, 302); // exit;

}

// === END OF REDIRECT BLOCK ===

0