読者です 読者をやめる 読者になる 読者になる

外部リダイレクトするApacheモジュール

CentOS5.1 上の Apache2.2のサンプル。

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "apr_tables.h"
#include "ap_config.h"

/* The sample content handler */
static int myredirect_handler(request_rec *r)
{
	apr_table_set(r->headers_out, "Location", "http://www.yahoo.com/");
	return HTTP_MOVED_TEMPORARILY;
}

static void myredirect_register_hooks(apr_pool_t *p)
{
    ap_hook_handler(myredirect_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA myredirect_module = {
    STANDARD20_MODULE_STUFF, 
    NULL,                  /* create per-dir    config structures */
    NULL,                  /* merge  per-dir    config structures */
    NULL,                  /* create per-server config structures */
    NULL,                  /* merge  per-server config structures */
    NULL,                  /* table of config file commands       */
    myredirect_register_hooks  /* register hooks                      */
};