Jump to content
desbest

My error 404 pages do not show

Recommended Posts

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?

Share this post


Link to post
Share on other sites

When I go to the link provided, I currently see a "sample swap feedback" image and sidebar without any errors. What is supposed to be displaying?

Share this post


Link to post
Share on other sites

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/

Share this post


Link to post
Share on other sites

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/";
  }
});

?>

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Just curious, is "daurl" a field you have defined in processwire? If not, i think you might need to use $page->url for the actual url of the page

Share this post


Link to post
Share on other sites

"daurl" is a field I've defined in processwire myself

 

my redirect page.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...