jumping the gun

Gezien Michel mijn development site in zijn dagelijkse del.icio.us lijst heeft opgenomen, heb ik (voorlopig) de URL errordoc-gewijs naar deze entry doorgelinked. Tenzij u het paswoord kunt raden.

Redirecten via een ErrorDocument directive met Apache is overigens heel eenvoudig. In een .htaccess file neemt u het volgende op:

  1. ErrorDocument 401 http://blog.volume12.net/2005/11/002550.htm
  2. AuthUserFile /pad/naar/.htpasswd
  3. AuthGroupFile /dev/null
  4. AuthName EnterPassword
  5. AuthType Basic
  6. require user username

waarbij u /pad/naar/.htpasswd vervangt door de locatie van uw .htpasswd, en de username door de door u gebruikte username. Een paswoord maken is overigens ook al eenvoudig.

[Update:] not quite:

Note that when you specify an ErrorDocument that points to a remote URL (ie. anything with a method such as “http” in front of it), Apache will send a redirect to the client to tell it where to find the document, even if the document ends up being on the same server. This has several implications, the most important being that the client will not receive the original error status code, but instead will receive a redirect status code. This in turn can confuse web robots and other clients which try to determine if a URL is valid using the status code. In addition, if you use a remote URL in an ErrorDocument 401, the client will not know to prompt the user for a password since it will not receive the 401 status code. Therefore, if you use an “ErrorDocument 401” directive then it must refer to a local document.

Simpel: dit stukje

  1. ErrorDocument 401 http://blog.volume12.net/2005/11/002550.htm

wijzigen naar

  1. ErrorDocument 401 /errordocs/401.php

En daarin (in 401.php) dan enkel dit plaatsen

  1. <?php
  2. header("Location: http://blog.volume12.net/2005/11/002550.htm");
  3. exit;
  4. ?>

Ofwel wijzigen naar

  1. ErrorDocument 401 /errordocs/401.htm

En daarin (in 401.htm) dan enkel dit plaatsen

  1. <meta HTTP-EQUIV="Refresh" CONTENT="0; URL=http://blog.volume12.net/2005/11/002550.htm">

En dan is er nog WordPress om mee af te rekenen, want dat doet zelf al een heleboel dingen met de errortoestanden en redirects (Authorization errors are handled by the WordPress program.).

[Update 2]: Het is niet nuttig een custom 401 document binnen het realm van de Require te plaatsen. Wij recapituleren even in een volgende entry.

2 gedachtes over “jumping the gun”

  1. Not to worry, het mocht gerust blijven staan. Het was bovendien plezant en nuttig ook: ik heb weer wat bijgeleerd over redirects etc.

Reacties zijn gesloten.