views:

290

answers:

7

Hi friends,

I have an issue I'm having trouble :/ err404 page's 200OK header status problem, although it should be 404 header. what is wrong with having 200 OK? is there really anything like that 200 OK should be at 404 error page header status?

appreciate advises!! thanks a lot!


i guess it has sth to do with .htaccess. here is my .htaccess file;

ErrorDocument 404 /err404.html

RewriteEngine On

RewriteRule ^login.html$ index.php?s=login&a=loginDo [QSA,L]
RewriteRule ^logout.html$ index.php?s=login&a=logoutDo [QSA,L]
RewriteRule ^([^/]*).html$ index.php?s=$1 [QSA,L]
RewriteRule ^members/([^/]*)$ index.php?s=profile&username=$1 [QSA,L]
RewriteRule ^([^/]*)/$ index.php?s=listing&search[cityString]=$1 [QSA,L]
RewriteRule ^([^/]*)/([^/]*)/$ index.php?s=listing&search[neighborhoodString]=$2 [QSA,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*).html$ index.php?s=details&seo_friendly=$3 [QSA,L]

i also have some more trouble related to this htaccess file :(

Question 1; when url is like http://localhost/fdfcdcvdvdvbdf.html (not exist url), it redirects to homepage, but it should redirect to err404.html. Any idea about the problem? err404 redirection works well in case of url like http://localhost/fdfcdcvdvdvbdf.ht or http://localhost/fdfcdcvdvdv

Question 2; How can I fix this 200 OK problem :/

+1  A: 

Well, the semantics of HTTP are pretty clear: if the page requested isn't found on the server, a 404 should be sent.

Also, if you don't mind having your site crawled/indexed with garbage (when there are pages not found)...

jldupont
+19  A: 

The 404 value is not just a Christmas tree decoration -- it conveys real information about the url in question, namely, that it doesn't exist. Sending a 200 page that describes the fact that the page doesn't exist is a completely different thing, particularly for a program, as opposed to a human.

Peter Rowell
+1 Thanks for *not* mentioning search engines. It seems that everyone just wants to please search engines in the first place.
Gumbo
When you see a question from someone who says *"my client is asking me to fix the code I'm selling but I don't see a reason why"*, mentioning search engines will resonate better than standard compliance. You have to remind people that by being lazy, they're not saving time, they're losing business.
Josh Davis
thanks for givin time @josh, but im not trying to save time here. im just trying to learn sth from the issue i have, im reading these comments and keep googling with the new information i get from here. im trying to learn good way to do things from my mistakes, not looking for ready code from anyone. thanks.
artmania
Sorry if I incorrectly assumed you were reluctant on acting on your client's complain then.
Josh Davis
Peter Rowell
+6  A: 

By returning a 200 OK status for missing pages, you're confusing browsers (may not show error messages if you had no custom error HTML) and search engines (they'll start indexing anything someone tells them about, like example.com/this-web-site-is-terrible-use-our-competitor)...


Regarding your edit about mod_rewrite:
http://example.com/lsdjkldsjlk.html matches your third RewriteRule, so it'll redirect to index.php.

The index.php script is where you should detect there's no content relating to the s parameter and return a 404 status via a call to header().

Christopher
yes @christopher i have noticed same about third line, but i couldnt find out how to sort that :/ i keep googling to find any exceptional case defining for no content existing page redirection, if there is anything like that.
artmania
Hm? In your index.php script, you must do some sort of content lookup based on the `s` parameter. If the content ID is invalid, then do a redirect to `error.php`. In that script, return the 404 status using PHP's `header()` method and then output whatever error-page content you like.
Christopher
yes, i made it for records, I put an ID control and redirect to error page. but I cant make it for pages like contact, home, aboutus, etc... there is no ID for these. so if I write blabla.com/sdfsfdsg it redirects to homepage, and i cant control such page with id :/ is there any trick to control not-exisiting file? i googled so much, but couldnot find anything.
artmania
This is what I've always believed. However, Yahoo recommends against 404 pages, yet does not provide further information:http://developer.yahoo.com/performance/rules.htmlAnyone know why?
Jaryl
That sounds more like they (the performance team) are recommending to make sure all your resources (especially JavaScripts) exist, as to download 404s wastes bandwidth and other consequences for browser performance. They also say that normally, customised 404s can be great for user experience.
Christopher
+3  A: 

For one thing, you probably don't want search engines indexing your 404 pages.

Andrew Medico
+1  A: 

It's not a 404 error page if it returns a 200 status. Anything that should fail if the page isn't available (caches, proxies, scripts) doesn't fail and chaos ensues. Also, Google will hate you (because spam sites return 200 pages for any queries.) Just return the damn 404 error.

Josh Davis
+1  A: 

By the way, do you know where does 404 in "404 error page" come from? It's exactly the HTTP error code.

The software should be able to distinguish between the correct and the wrong pages. If you send a page with "404" in it as an image, no software would ever recognize that something is wrong.

Vlad
+2  A: 

It's an accessibility issue. 200 OK means that the resource sent out is the resource requested. 404 means the resource requested could not be found and the resource sent out is an error page. Browsers use the status code you send to know if everything is okay. You may not notice any difference on the displayed page as a human, but crawlers do need to know such things (or they'll index your errors and such).

Kris