Page 2 of 4

Re: Custom errordocs not working in IE10

Posted: Tue Nov 26, 2013 3:18 pm
by Eric!
Are you using a framework?

Since you are parsing the URL (probably with categ.php) to find pages then your program has to redirect to the error page. So instead of producing a page with a meta refresh, just produce the error html.

Re: Custom errordocs not working in IE10

Posted: Tue Nov 26, 2013 3:22 pm
by simonmlewis
Sorry you've lost me now.
The issue is, for SEO purposes mostly, I need to force users to the 404 page, which in turns takes them to my index.php?page=oops page.
Whether that be a meta refresh (which IE10 conveniently can ignore) or thru HTACCESS, I don't know.
Neither work in IE10.

A Framework??

Re: Custom errordocs not working in IE10

Posted: Tue Nov 26, 2013 3:44 pm
by Eric!
Ok, so you're not using a framework.

index.php will always be found by apache so htaccess won't do anything on a 404 error because index.php exists.

index.php?page=apagethatdoesnotexist will also always be found by apache because index.php exists. Again htaccess won't ever get a 404 error.

index.php?page=pagethatdoesnotexist to go to your oops page should simply do one of the following:

General redirect inside index.php:

Code: Select all

header("Location: /oops.php",TRUE,404);
die();
OR Make index.php do something clever itself:
1. Report to the user a 404 error occurred

Code: Select all

header("Status: 404 Not Found");
2. Search for "pagethatdoesnotexit" and make some suggestions

OR Make index.php do something more clever:
1. Create a database for all 404 pages, then add corrections to them on the fly. And log missing pages.
2. index.php can't find a page, check the database, see if there is a match to a real page and use it with a redirect:

Code: Select all

// 301 Moved Permanently
header("Location: /index.php?page=my_exiting_page",TRUE,301);
die();
3. otherwise present 404 and search results
4. site admin needs a little tool to go through all the missing pages that get logged by index.php and enter corrections manually. So say people keep hitting index.php?page=my_paeg1. In the database you can map my_paeg1 to my_page1, so users aren't bothered by typos, or long links they can't spell, or bad links that someone posted somewhere else in error with a typo.

Re: Custom errordocs not working in IE10

Posted: Tue Nov 26, 2013 3:49 pm
by simonmlewis
Thx for all this, however right now, I simply want one thing: for IE10 to accept and take the user to the not_found.html file in error_docs.
If it basically cannot be done, because IE10 is set NOT to do that, then I'm screwed and have to accept that only the other browsers "behave".

I'm not interested in capturing the "missing" urls for now. Perhaps some day but that is not my priority here. That is to take them to the error page.

Re: Custom errordocs not working in IE10

Posted: Tue Nov 26, 2013 6:08 pm
by Eric!
You shouldn't design your code so that the user is dependent on a meta tag to work. At a minimum use the first suggestion I made.

That method is the industry standard. Spiders will understand what is happening rather than hoping they will follow some meta-tag and figure out what is going on. If you want SEO to work consistently then use the header redirect.

If a spider goes to your missing page and you are not providing error status codes and just producing 200 OK codes then even if a spider follows the meta redirect it is going to index your oops page as the result, not as an error. So yourdomain.com/index.php?page=this_sucks would show up with results containing the text of your oops error page. This is not the behavior you probably want from a search engine unless you really want people to see your error page.

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 2:46 am
by simonmlewis
So how do I do that just once, in the index.php template?

Code: Select all

$page = isset($_GET['page']) ? $_GET['page'] : null;
if (isset($page))
{
  function getPage()
  {
  $thispage="includes/".$_GET['page'].".inc";

  if (file_exists($thispage)) 
  {
   include $thispage;
  } 
  else 
  {
  echo "<meta http-equiv='Refresh' content='0 ;URL=/'>";
  }
  }
  }   
Or must it go into the include file?
I suspect the above bears no relation to it, as that isn't down to the categ.inc file existing, because the page called IS categ.inc.

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 2:57 am
by simonmlewis

Code: Select all

header("Location: /oops",TRUE,404);
die();
Where exactly does this go?
I tried it just inside the top <?php and it kills the site.

I've been reading about these headers and seems a good thing to do, but I just cannot see where it goes. I've tried it before and after the start of a session.

Just doesn't work. I'm clearly doing something wrong.

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 1:36 pm
by Eric!
Since you didn't post the full code, we can only guess at what you're doing wrong. First off check your error logs or turn on error reporting. I bet you'll find:

[text]Warning: Cannot modify header information - headers already sent by (output started at /some/file.php:xx) in /some/file.php on line xx[/text]

Then the next step is to google this error and learn about how to fix it.

Or the path or filename is wrong because you just copy and pasted my example which doesn't have a path or a file extension....

Code: Select all

header("Location: /what_is_your_path/oops.php",TRUE,404); // .php .html .666 ?
die();

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 1:41 pm
by simonmlewis
Sorry yes. But the file path is httpdocs/includes/oops.inc. so I assumed the general /oops was fine.
I think display errors was off. My bad!
What should my location be based on that?

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 1:47 pm
by simonmlewis
Here is the code right slap-bang at the top.
I am getting no error codes at all on the page, because the Location is wrong?

I am running this locally, so if the the error_docs folder is within the site folder, surely this is correct??

All I get as a rendered result is - when I do View Source,
[text]1
2[/text]

Code: Select all

<?php session_start(); 
header("Location: /error_docs/not_found.html",TRUE,404);
die();

function curHomeURL()
{
 $pagehomeURL = (isset($_SERVER['HTTPS']) && ($_SERVER["HTTPS"] == "on")) ? 'https://' : 'http://';
 if ($_SERVER["SERVER_PORT"] != "80") 
 {
  $pagehomeURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  } 
  else 
 {
  $pagehomeURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pagehomeURL;
}
$urlhome = curHomeURL();

include "dbconn.php";

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 3:19 pm
by Eric!
simonmlewis wrote: All I get as a rendered result is - when I do View Source,
[text]1
2[/text]
You're going to have to solve that riddle because the code that you posted should not produce that output. Does the browser URL indicate the change from index.php to http://localhost/error_docs/not_found.html ?

Does http://localhost/error_docs/not_found.html exist? Does it output 1 2 when you put it in directly?

Do you know how to use a browser plug-in like LIVE HTTP HEADERS to capture your site's headers?

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 3:23 pm
by simonmlewis
It doesn't, it remains on that URL I tried (which is an invalid page).
No I have not heard of that plugin - is it a firefox one?

Re: Custom errordocs not working in IE10

Posted: Wed Nov 27, 2013 6:18 pm
by Eric!
Yes, firefox. Are you not getting any errors in the apache log?

Re: Custom errordocs not working in IE10

Posted: Thu Nov 28, 2013 2:31 am
by simonmlewis
There are no errors in the log in the live server for this.

Re: Custom errordocs not working in IE10

Posted: Thu Nov 28, 2013 11:46 am
by Eric!
No errors lead me to look test it and look at the headers and I realized I made a mistake. My bad. You can't use the 404 error code and a redirect at the same time. You can do something like this in your index.php file:

Option 1

Code: Select all

header("Status: 404 Not Found");
include_once("/error_docs/not_found.html");
die();
Or option 2 index.php:

Code: Select all

header("Location: /error_docs/not_found.html",TRUE,302); //404 error won't get the browser to redirect
die();
And then in your not_found.html page, add this at the very top (assuming your server is setup to parse php in .html files):

Code: Select all

<?php header("Status: 404 Not Found"); ?>
Either way at some point you need to generate the 404 status code so spiders know they hit a dead end.