{"id":444,"date":"2012-05-23T10:08:14","date_gmt":"2012-05-23T10:08:14","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=444"},"modified":"2012-05-23T10:08:14","modified_gmt":"2012-05-23T10:08:14","slug":"personnaliser-les-pages-erreurs-via-htaccess","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=444","title":{"rendered":"Personnaliser les pages erreurs via .htaccess"},"content":{"rendered":"<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\"><strong>one<\/strong> <strong><strong>of<\/strong><\/strong> <strong><strong>the<\/strong><\/strong> <strong>most<\/strong> <strong>d<strong>is<\/strong>cussed<\/strong> <strong>topics<\/strong> <strong>here<\/strong> <strong>is<\/strong> <strong><strong>the<\/strong><\/strong> <strong>importance<\/strong> <strong><strong>of<\/strong><\/strong> a <strong><strong>404<\/strong><\/strong> <strong>page<\/strong> <strong>returning<\/strong> a &#8220;<strong>real<\/strong>&#8221; <strong><strong>404<\/strong><\/strong> <strong>header<\/strong>. Amazingly, <strong><strong>the<\/strong><\/strong>re are thousands <strong><strong>of<\/strong><\/strong> &#8220;custom <strong><strong>404<\/strong><\/strong> error tutorials&#8221; on <strong><strong>the<\/strong><\/strong> web that don&#8217;t touch th<strong>is<\/strong> <strong>is<\/strong>sue. If you set up a custom <strong><strong>404<\/strong><\/strong> using .htaccess, <strong><strong>the<\/strong><\/strong> server will still return a status <strong><strong>of<\/strong><\/strong> 200 OK, because <strong><strong>the<\/strong><\/strong> original status <strong>is<\/strong> lost in <strong><strong>the<\/strong><\/strong> redirect. Th<strong>is<\/strong> <strong>is<\/strong> a &#8220;big deal.&#8221; <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">For <strong><strong>the<\/strong><\/strong> unaware, let&#8217;s take <strong><strong>the<\/strong><\/strong> worst case: you set up a <strong><strong>404<\/strong><\/strong> to redirect to <strong><strong>the<\/strong><\/strong> home <strong>page<\/strong>. <strong>page<\/strong> not found, put <strong><strong>the<\/strong><\/strong>m back on main <strong>page<\/strong>. Bad idea, if <strong><strong>the<\/strong><\/strong> search engines capture a few bad links, <strong><strong>the<\/strong><\/strong>y are going to index your <strong><strong>404<\/strong><\/strong> <strong>page<\/strong> &#8211; which <strong>is<\/strong> duplicate content for your main <strong>page<\/strong>, which gives you duplicate content penalties. For your main <strong>page<\/strong>. OUCH. <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">Secondly, many have had trouble creating <strong><strong>the<\/strong><\/strong>ir Google site verification <strong>page<\/strong> because <strong><strong>the<\/strong><\/strong>y use a custom <strong><strong>404<\/strong><\/strong> <strong>page<\/strong>, as Google won&#8217;t verify a site that returns a 200 for a non-ex<strong>is<\/strong>tent <strong>page<\/strong>. <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">So I&#8217;ve spent a few hours th<strong>is<\/strong> AM looking around. Unfortunately, I was only able to locate two veins <strong><strong>of<\/strong><\/strong> comments on <strong>how to get a custom error <strong>page<\/strong> to return a <strong><strong>404<\/strong><\/strong> <strong>header<\/strong>.<\/strong> Th<strong>is<\/strong> first was helpful comments supplying no <strong>real<\/strong> resolution: <\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\">a URL that does not ex<strong>is<\/strong>t should be <strong>returning<\/strong> a <strong><strong>404<\/strong><\/strong> [Not Found] <\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\"><br \/>\n<\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\">Some domains have improperly configured <strong><strong>the<\/strong><\/strong>ir custom error <strong>page<\/strong> . . . <\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\"><br \/>\n<\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\"><br \/>\nYou need to make sure your custom error <strong>page<\/strong> returns a proper <strong><strong>404<\/strong><\/strong> <strong>header<\/strong>. If you&#8217;re <strong>returning<\/strong> a 200 OK, Sitemaps won&#8217;t verify your site. <\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">OKAY, we get it, <strong><strong>the<\/strong><\/strong> custom error &#8220;<strong>page<\/strong>&#8221; needs to generate a <strong><strong>404<\/strong><\/strong> <strong>header<\/strong>. So how do we do that? <strong><strong>the<\/strong><\/strong> reason for quoting &#8220;<strong>page<\/strong>&#8221; became apparent when I encountered th<strong>is<\/strong>: <\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\">DO NOT use static html <strong>page<\/strong>s for th<strong>is<\/strong> &#8212; you can&#8217;t change <strong><strong>the<\/strong><\/strong> result code on a static html <strong>page<\/strong>. <\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">Now we&#8217;re getting down to it &#8211; when we think <strong><strong>of<\/strong><\/strong> &#8220;<strong>page<\/strong>s&#8221; <strong>most<\/strong> <strong><strong>of<\/strong><\/strong> us think <strong><strong>of<\/strong><\/strong> <em>static html.<\/em> An .asp <strong>page<\/strong>, php <strong>page<\/strong>, or a perl scripts are <strong>real<\/strong>ly dynamic <strong>page<\/strong> output and not static <strong>page<\/strong>s. Yet al<strong>most<\/strong> every resource on <strong><strong>the<\/strong><\/strong> web on custom error <strong>page<\/strong>s instructs to create a static <strong>page<\/strong> to a custom error <strong>page<\/strong>. <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">&lt;debate&gt;<br \/>\n<strong><strong>the<\/strong><\/strong> second bit <strong><strong>of<\/strong><\/strong> m<strong>is<\/strong>information I encountered that using a forward -slash path in your directive will preserve <strong><strong>the<\/strong><\/strong> <strong><strong>404<\/strong><\/strong> status: <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">ErrorDocument <strong><strong>404<\/strong><\/strong> \/my_error.html <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">Th<strong>is<\/strong> <strong>is<\/strong> also (apparently?) false, I have tested it thoroughly, an error document at root still returns 200 <strong>header<\/strong>s when <strong><strong>the<\/strong><\/strong> <strong>page<\/strong> <strong>is<\/strong> d<strong>is<\/strong>played because it loses <strong><strong>the<\/strong><\/strong> original <strong><strong>404<\/strong><\/strong> in <strong><strong>the<\/strong><\/strong> redirect.<br \/>\n&lt;\/debate&gt; <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\"><strong><strong>the<\/strong><\/strong> second vein <strong><strong>of<\/strong><\/strong> comments has to do with solving th<strong>is<\/strong> <strong>is<\/strong>sue but what I still consider <strong>workarounds:<\/strong> <\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\">Temporarily d<strong>is<\/strong>able custom <strong><strong>404<\/strong><\/strong> error <strong>page<\/strong>s for your site\/Check if your web server return correct <strong><strong>404<\/strong><\/strong> code for non ex<strong>is<\/strong>ting <strong>page<\/strong>s\/verify file\/Restore your <strong><strong>404<\/strong><\/strong> custom error <strong>page<\/strong>s. <\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">Th<strong>is<\/strong> will work for getting past <strong><strong>the<\/strong><\/strong> Google verification, but you still have a permanent <strong>is<\/strong>sue with non ex<strong>is<\/strong>tent <strong>page<\/strong>s generating a 200 OK. <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">Because static HTML won&#8217;t generate http <strong>header<\/strong>s, a <em>scripting method<\/em> <strong>is<\/strong> <strong><strong>the<\/strong><\/strong> suggested usage in <strong>most<\/strong> cases. <\/span><\/p>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">PHP:<br \/>\n<\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\"><br \/>\n&lt;?php<br \/>\n<strong>header<\/strong>(&#8220;HTTP\/1.0 <strong><strong>404<\/strong><\/strong> Not Found&#8221;);<br \/>\n?&gt;<br \/>\n<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">ASP:<br \/>\n<\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\"><br \/>\n&lt;%<br \/>\nResponse.Status = &#8220;<strong><strong>404<\/strong><\/strong> Not Found&#8221;<br \/>\n%&gt;<br \/>\n<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\">Perl:<br \/>\n<\/span><\/p>\n<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#333333\">\n<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td bgcolor=\"#f2f2ff\"><span style=\"color: #222222; font-family: arial; font-size: x-small;\"><br \/>\nprint &#8220;Status: HTTP\/1.1 <strong><strong>404<\/strong><\/strong> Not Foundn&#8221;;<br \/>\nprint &#8220;Content-type: text\/htmlnn&#8221;;<br \/>\n<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #000000; font-family: verdana; font-size: x-small;\"><strong>So <strong>here<\/strong> <strong>is<\/strong> <strong><strong>the<\/strong><\/strong> question:<\/strong> I still consider <strong><strong>the<\/strong><\/strong>se workarounds. I have my perl scripts printing <strong><strong>the<\/strong><\/strong> <strong><strong>404<\/strong><\/strong> status w<strong>here<\/strong> appropriate, but it seems like <strong><strong>the<\/strong><\/strong>se shouldn&#8217;t be necessary. <strong>is<\/strong> <strong><strong>the<\/strong><\/strong>re a CORRECT way to simply use <strong><strong>the<\/strong><\/strong> <strong><strong>404<\/strong><\/strong> directive to our advantage without relying on an external tool to return <strong><strong>the<\/strong><\/strong> appropriate <strong>header<\/strong>? <\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Il existe pas mal de templates pr\u00e9-existants pour avoir une mise en page bien plus belle que celle g\u00e9n\u00e9r\u00e9e par Apache.<\/p>\n<p>Tout d\u2019abord, ajoutez ceci dans votre fichier .htacess \u00e0 la racine ou le r\u00e9pertoire concern\u00e9.<\/p>\n<p>ErrorDocument 301 \/erreurs\/301-moved_permanently.php<br \/>\nErrorDocument 302 \/erreurs\/302-moved_temporarily.php<br \/>\nErrorDocument 303 \/erreurs\/303-see_other.php<br \/>\nErrorDocument 400 \/erreurs\/400-bad_request.php<br \/>\nErrorDocument 401 \/erreurs\/401-authorization_required.php<br \/>\nErrorDocument 402 \/erreurs\/402-payment_required.php<br \/>\nErrorDocument 403 \/erreurs\/403-forbidden.php<br \/>\nErrorDocument 404 \/erreurs\/404-not_found.php<br \/>\nErrorDocument 405 \/erreurs\/405-method_not_allowed.php<br \/>\nErrorDocument 406 \/erreurs\/406-not_acceptable.php<br \/>\nErrorDocument 407 \/erreurs\/407-proxy_authentication_required.php<br \/>\nErrorDocument 408 \/erreurs\/408-request_timed_out.php<br \/>\nErrorDocument 409 \/erreurs\/409-conflicting_request.php<br \/>\nErrorDocument 410 \/erreurs\/410-gone.php<br \/>\nErrorDocument 411 \/erreurs\/411-content_length_required.php<br \/>\nErrorDocument 412 \/erreurs\/412-precondition_failed.php<br \/>\nErrorDocument 413 \/erreurs\/413-request_entity_too_long.php<br \/>\nErrorDocument 414 \/erreurs\/414-request_uri_too_long.php<br \/>\nErrorDocument 415 \/erreurs\/415-unsupported_media_type.php<br \/>\nErrorDocument 500 \/erreurs\/500-internal_server_error.php<br \/>\nErrorDocument 501 \/erreurs\/501-not_implemented.php<br \/>\nErrorDocument 502 \/erreurs\/502-bad_gateway.php<br \/>\nErrorDocument 503 \/erreurs\/503-service_unavailable.php<br \/>\nErrorDocument 504 \/erreurs\/504-gateway_timeout.php<br \/>\nErrorDocument 505 \/erreurs\/505-http_version_not_supported.php<\/p>\n","protected":false},"excerpt":{"rendered":"<p>one of the most discussed topics here is the importance of a 404 page returning a &#8220;real&#8221; 404 header. Amazingly, there are thousands of &#8220;custom 404 error tutorials&#8221; on the web that don&#8217;t touch&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2849,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[29],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/444"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=444"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/444\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2849"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}