404 Error

Started by endomorph, December 22, 2010, 06:02:03 AM

Previous topic - Next topic

endomorph

Why is it that if you try o open a page that does not exists, the forum defaults to index.php but does not throw a 404 header.

I have tried adding a custom page into .htaccess but it still defaults to inde.php

My .htaccess looks like

ErrorDocument 404 /index.php?action=ezportal;sa=page;p=11

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php


But not sure if this is correct

Illori


endomorph

Thanks but no, I'm on a Windows box not Apache


Illori

you can run apache under windows.

endomorph


Illori

apache is part of what runs the webserver, not what os you are running. a 404 error would be an error from your webserver not your os.

MrPhil

Quote from: endomorph on December 22, 2010, 06:02:03 AM
ErrorDocument 404 /index.php?action=ezportal;sa=page;p=11

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php

You told .htaccess to direct all invalid files or directories to index.php. There's nothing left for the server to raise a 404 on. Presumably you have some sort of SEO mod installed. If it can't figure out what to do with the URL (i.e., rewrite it to a real directory and filename), it could have its own "internal" 404 page of some sort, or just send the visitor to some "home" page. BTW, does .htaccess allow URL Query Strings (action=ezportal;sa=page;p=11) on an ErrorDocument?

QuoteEh ????
Linux servers generally run Apache webservers. They definitely cannot run IIS (Microsoft's webserver). Windows servers usually run IIS, but can run Apache (there are Windows versions). And 1) learn to preview your posts, so multiple question marks don't catch you by surprise, and 2) learn how to use the "Attachments and other options" to turn off smileys.

Arantor

And if you're using .htaccess, you definitely aren't using IIS since that doesn't support them...

endomorph

QuoteBTW, does .htaccess allow URL Query Strings (action=ezportal;sa=page;p=11) on an ErrorDocument?

This is probably the problem then. I will try sending it to a fixed file.

QuoteAnd if you're using .htaccess, you definitely aren't using IIS since that doesn't support them...

ISAPI_Rewrite 3 for IIS

Arantor

Wait... ISAPI_Rewrite deals with rewrite rules from what I remember, last I saw of it, it didn't support ErrorDocuments because they're not rewrite rules, as in it's not a full replacement for all the directives in .htaccess.

endomorph

Ah ! So is there a re-write rule for 404 ?

Arantor

Doesn't really matter anyway since MrPhil hit the nail on the head:

QuoteYou told .htaccess to direct all invalid files or directories to index.php

You want it to redirect to that custom page on directories or files not being found, don't redirect to index.php on its own...

MrPhil

Quote from: IncognitoMuse on December 23, 2010, 12:01:33 PM
Doesn't really matter anyway since MrPhil hit the nail on the head:
Nah, I hit my thumb that was holding the nail...

Quote
You want it to redirect to that custom page on directories or files not being found, don't redirect to index.php on its own...
Hold on a moment. You have a redirect in your ".htaccess" (or whatever the IIS rewrite equivalent is) to send everything to index.php. You must have put it there for a reason, right? Do you have some sort of SEO mod installed? Or are you just throwing in everything you've ever seen into it? If you're not doing SEO, and just want to send invalid URLs to some special page, it's easy enough to do in Apache but I'm not sure how IIS works. If you are doing SEO, you need to have your routine that you redirect to do all the error handling.

Why aren't you doing this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?action=ezportal;sa=page;p=11

(Assuming IIS rewrite can handle those conditions.) This probably means no SEO, just capturing all 404s.

endomorph

OK I think I am getting there. Thanks for your help MrPhil. Took your advice and I am sending it to 404.php which is a SSI based file (I think)

Code is -


<?php 
//Require header.php
require('header.php'); 
?>



Some page text stuff

<?php 
//Require Footer,php
require('footer.php'); 
?>



But how do I give a server header of 404 ?

Arantor

<?php 
//Require header.php
header('404 File Not Found');
require(
'header.php'); 
?>



Some page text stuff

<?php 
//Require Footer,php
require('footer.php'); 
?>


Note, the header() should be the very first thing.

endomorph

Nope, still getting a 200 OK

endomorph

OK found out why. In IIS you need to use -

header("Status: 404 Not Found");

Arantor

Actually, you needed to have that regardless, it's been that long since I did it, I forgot you needed the Status part, my bad.

Advertisement: