Jump to content

Recommended Posts

Posted

My error pages do not show on my website. [see here]
My web browser Firefox shows this error

Quote

The page isn't redirecting properly

An error occurred during a connection to hostingz.org.

 This problem can sometimes be caused by disabling or refusing to accept cookies.

 

I have no PHP on the error404.php template.

What is going on, and how do I fix it?

Posted

Did it used to work previously?

The response header for a non-existing site shows HTTP 302. It means there's something wrong with your setup. Check the .htaccess file first.

Maybe you have set up your own redirects, either manually in .htaccess, or with a module (e.g. this one) inside PW admin. Or maybe even a hook. Check the logs if you find something suspicious.

https://processwire.com/docs/start/install/troubleshooting/

Posted

I've made my own redirect template for redirecting url's like http://hostingz.org/indicho

I think this redirect template is conflicting with the error 404 page.
 

<?php

function bot_detected() {

  return (
    isset($_SERVER['HTTP_USER_AGENT'])
    && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])
  );
}

if (bot_detected() === true){
    //echo "is a bot";
} else {
    //echo "not a bot";
    $hitcount = $page->views;
    $newhitcount = $page->views +1;
    //add 1 to the view counter
    $daview = $pages->get($page->id);
    $daview->of(false);
    $daview->views = $newhitcount;
    $daview->save();
    //save the higher value onto the link page
}

$session->redirect($page->daurl);
//redirect to link

?>

and there's _init.php
 

<?php

$pages->addHookBefore('Page::path', function($event) {
  $page = $event->object;
  if($page->template == 'post') {// template used by 'post-a'
    // ensure that pages with template 'post' live off the root rather than '/posts/'
    $event->replace = true;
    $event->return = "/$page->name/";
  }
});

?>

 

Posted
11 hours ago, desbest said:

$session->redirect($page->daurl);

I think that could be the problem. The redirect for the 404 page comes back without a value in the location header. It might be as easy as checking whether the current page id equals $config->http404PageID to decide whether to redirect or not.

Posted

Hello I've updated the code to

if ($page->id != $config->http404PageID) { $session->redirect($page->daurl); }
//redirect to link

and it still doesn't work

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...