Hi,
Is there an easy, simple and safe piece of code to put on the .htaccess file in order to redirect all 404 not found pages to the home page?
Or can it be done on a specific file?
My 404 pages state theat they are redirecting the customer bu they don't, so I needed to redirect them to the home page.
Thank you,
Tânia
In "fn.control.php" file located in the "app" directory of your CS-Cart installation, replace the following part of code:
if ($status == CONTROLLER_STATUS_NO_PAGE) {
header(' ', true, 404);
}
with this one:
if ($status == CONTROLLER_STATUS_NO_PAGE) {
fn_redirect(Registry::get('config.http_location') . "/index.php");
}
Better give them a message or they will be totally confused. I.e.
if ($status == CONTROLLER_STATUS_NO_PAGE) {
fn_set_notification("E", __("error"), __("page_not_found"), 'K');
fn_redirect(Registry::get('config.http_location') . "/index.php");
}
1 Like
Hi,
In "fn.control.php" file located in the "app" directory of your CS-Cart installation, replace the following part of code
if ($status == CONTROLLER_STATUS_NO_PAGE) {
header(' ', true, 404);
}
My app/functions/fn.control.php file has a few more lines of code, not just these lines, mine is:
if ($status == CONTROLLER_STATUS_NO_PAGE) {
if ($area == 'A' && empty($auth['user_id'])) {
// If admin is not logged in redirect to login page from not found page
fn_set_notification('W', __('page_not_found'), __('page_not_found_text'));
fn_redirect("auth.login_form");
}
header(' ', true, 404);
I tried to replace just the last line with the one you gave but the shop crashes.
I really need to redirect the 404 pages because of my recent upgrade from a very old store, after the upgrade many of the URL's where changed, we fixed most of them but there are plenty more unsolvable.
For example, my old store used this this type of URL: "index.php?dispatch=news.view&news_id="
and on my upgraded store this URL has changed, I could do by hand the 301 redirections but I no longer know what is what as I don't have the old URL's correspondance.
On my analytics software I see visitors fleying the store when they enter these 404 pages, so I rather have them redirected to the home page instead.
Replace:
header(' ', true, 404);
with
if (AREA == 'C') {
fn_set_notification("E", __("error"), __("page_not_found"), 'K');
fn_redirect(Registry::get('config.http_location') . "/index.php");
}
header(' ', true, 404);
It works!!! Thank you ecom :-)
Ps: I commented out the error part of the code, sorry, don't like the red error popup that does not auto disapear. :roll: