2

I am looking for a way to redirect joomla to a different page without changing the url in the address bar.

We currently have a site setup that when it encounters a 404 page (eg. site.com/fake-url) it redirects to a custom 404 page (site.com/404-page). This 404 page is an article page with custom modules etc. designed to help the user in finding the correct page.

However we now desire to keep the person on the incorrect url they entered and display the custom 404 page. I know it is possible via htaccess redirects to silently redirect without changing the url I am wondering if something like this is possible for joomla.

The current code that redirects is found in the templates error.php file

if($this->error->getCode() == "404"){
    $link = JRoute::_("index.php?option=com_content&view=article&id=82&Itemid=163");
    $app->redirect($link);
}
0

1 Answer 1

1

Although not using proper terminology, I think I got what your main problem is.

First of all, what you have now is not a right way to deal with non-found pages/urls (404 errors). Actually you don't return a 404 status error, instead you return a 200 status page with content. So it looks like any faulty url leads to somewhere in your site.

Then you don't need another redirection nor anything "silent" or "mystic".

What you need to do is to work on your template's error.php page. To start on this, simply remove this wrongly used redirection in your error.php.

Test to see the results now with a /fake-url page. If the rest of your error.php is correct (with SEF URLs enabled as well), you should see that you remain on the non-existing URL, with a 404 status error and whatever content your error.php is designed to show.

Now all you have to do is to be creative with the error.php file. This Joomla Documentation resource should help: Custom Error Pages

If you have other issues with customizing your error page, feel free to open a new question in this website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.