Reputation: 6064
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 :/
Upvotes: 4
Views: 6206
Reputation: 111565
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()
.
Upvotes: 7
Reputation: 28730
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.
Upvotes: 2
Reputation: 41837
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).
Upvotes: 1
Reputation: 35594
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.
Upvotes: 2
Reputation: 20174
For one thing, you probably don't want search engines indexing your 404 pages.
Upvotes: 3
Reputation: 17713
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.
Upvotes: 21
Reputation: 96716
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)...
Upvotes: 3