Personnaliser les pages erreurs via .htaccess

one of the most discussed topics here is the importance of a 404 page returning a “real404 header. Amazingly, there are thousands of “custom 404 error tutorials” on the web that don’t touch this issue. If you set up a custom 404 using .htaccess, the server will still return a status of 200 OK, because the original status is lost in the redirect. This is a “big deal.”

For the unaware, let’s take the worst case: you set up a 404 to redirect to the home page. page not found, put them back on main page. Bad idea, if the search engines capture a few bad links, they are going to index your 404 page – which is duplicate content for your main page, which gives you duplicate content penalties. For your main page. OUCH.

Secondly, many have had trouble creating their Google site verification page because they use a custom 404 page, as Google won’t verify a site that returns a 200 for a non-existent page.

So I’ve spent a few hours this AM looking around. Unfortunately, I was only able to locate two veins of comments on how to get a custom error page to return a 404 header. This first was helpful comments supplying no real resolution:

a URL that does not exist should be returning a 404 [Not Found]

Some domains have improperly configured their custom error page . . .

You need to make sure your custom error page returns a proper 404 header. If you’re returning a 200 OK, Sitemaps won’t verify your site.

OKAY, we get it, the custom error “page” needs to generate a 404 header. So how do we do that? the reason for quoting “page” became apparent when I encountered this:

DO NOT use static html pages for this — you can’t change the result code on a static html page.

Now we’re getting down to it – when we think ofpages” most of us think of static html. An .asp page, php page, or a perl scripts are really dynamic page output and not static pages. Yet almost every resource on the web on custom error pages instructs to create a static page to a custom error page.

the second bit of misinformation I encountered that using a forward -slash path in your directive will preserve the 404 status:

ErrorDocument 404 /my_error.html

This is also (apparently?) false, I have tested it thoroughly, an error document at root still returns 200 headers when the page is displayed because it loses the original 404 in the redirect.

the second vein of comments has to do with solving this issue but what I still consider workarounds:

Temporarily disable custom 404 error pages for your site/Check if your web server return correct 404 code for non existing pages/verify file/Restore your 404 custom error pages.

This will work for getting past the Google verification, but you still have a permanent issue with non existent pages generating a 200 OK.

Because static HTML won’t generate http headers, a scripting method is the suggested usage in most cases.


header(“HTTP/1.0 404 Not Found”);


Response.Status = “404 Not Found”


print “Status: HTTP/1.1 404 Not Foundn”;
print “Content-type: text/htmlnn”;

So here is the question: I still consider these workarounds. I have my perl scripts printing the 404 status where appropriate, but it seems like these shouldn’t be necessary. is there a CORRECT way to simply use the 404 directive to our advantage without relying on an external tool to return the appropriate header?



Il existe pas mal de templates pré-existants pour avoir une mise en page bien plus belle que celle générée par Apache.

Tout d’abord, ajoutez ceci dans votre fichier .htacess à la racine ou le répertoire concerné.

ErrorDocument 301 /erreurs/301-moved_permanently.php
ErrorDocument 302 /erreurs/302-moved_temporarily.php
ErrorDocument 303 /erreurs/303-see_other.php
ErrorDocument 400 /erreurs/400-bad_request.php
ErrorDocument 401 /erreurs/401-authorization_required.php
ErrorDocument 402 /erreurs/402-payment_required.php
ErrorDocument 403 /erreurs/403-forbidden.php
ErrorDocument 404 /erreurs/404-not_found.php
ErrorDocument 405 /erreurs/405-method_not_allowed.php
ErrorDocument 406 /erreurs/406-not_acceptable.php
ErrorDocument 407 /erreurs/407-proxy_authentication_required.php
ErrorDocument 408 /erreurs/408-request_timed_out.php
ErrorDocument 409 /erreurs/409-conflicting_request.php
ErrorDocument 410 /erreurs/410-gone.php
ErrorDocument 411 /erreurs/411-content_length_required.php
ErrorDocument 412 /erreurs/412-precondition_failed.php
ErrorDocument 413 /erreurs/413-request_entity_too_long.php
ErrorDocument 414 /erreurs/414-request_uri_too_long.php
ErrorDocument 415 /erreurs/415-unsupported_media_type.php
ErrorDocument 500 /erreurs/500-internal_server_error.php
ErrorDocument 501 /erreurs/501-not_implemented.php
ErrorDocument 502 /erreurs/502-bad_gateway.php
ErrorDocument 503 /erreurs/503-service_unavailable.php
ErrorDocument 504 /erreurs/504-gateway_timeout.php
ErrorDocument 505 /erreurs/505-http_version_not_supported.php


Since 20 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions. I am an experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. When not writing code, I like to dance salsa and swing and have fun with my little family.

You may also like...

Leave a Reply