This shows the processing order combined with this special case where an other handler is set and the redirect-handler is overridden and if (strcmp(r->handler, "redirect-handler")) { return DECLINED; } in mod_rewrite.c returns DECLINED (this has nothing to do with the trailing slash, because /var/www/a does not exist as folder but belongs to the past processing of hooks issue). RewriteEngine on RewriteRule ^a /test/index.foo [H=application/x-cgi-php] Request: /a error log [Thu Aug 31 17:58:50 2006] [debug] request.c(111): [client 127.0.0.1] ##############ap_process_request_internal()############## with r->parsed_uri.path /a, r->the_request: GET /a HTTP/1.1, d->handler: (null) [Thu Aug 31 17:58:50 2006] [debug] mod_rewrite.c(4149): [client 127.0.0.1] mod_rewrite: hook hook_uri2file with r->uri: /a, r->filename: (null), r->the_request: GET /a HTTP/1.1 [Thu Aug 31 17:58:50 2006] [debug] mod_rewrite.c(4424): [client 127.0.0.1] mod_rewrite: hook hook_fixup with r->uri: /a, r->filename: /var/www/a, r->handler: (null), dconf->directory: /var/www/, r->the_request: GET /a HTTP/1.1 [Thu Aug 31 17:58:50 2006] [debug] mod_rewrite.c(4691): [client 127.0.0.1] mod_rewrite: hook hook_fixup: setting r->handler = redirect-handler; with r->uri: /a, r->filename: redirect:/test/index.foo, r->the_request: GET /a HTTP/1.1 [Thu Aug 31 17:58:50 2006] [debug] mod_dir.c(104): [client 127.0.0.1] mod_dir: hook fixup_dir with r->uri: /a, r->filename: redirect:/test/index.foo, r->handler: redirect-handler [Thu Aug 31 17:58:50 2006] [debug] mod_rewrite.c(4712): [client 127.0.0.1] mod_rewrite: hook hook_mimetype with r->uri: /a, r->filename: redirect:/test/index.foo, r->handler: redirect-handler, r->the_request: GET /a HTTP/1.1 [Thu Aug 31 17:58:50 2006] [debug] mod_rewrite.c(4742): [client 127.0.0.1] mod_rewrite: hook handler_redirect with r->uri: /a, r->filename: redirect:/test/index.foo, r->handler: application/x-cgi-php, r->the_request: GET /a HTTP/1.1 # because r->handler is not set to "redirect-handler" anymore, ap_internal_redirect() is not called. [Thu Aug 31 17:58:50 2006] [error] [client 127.0.0.1] File does not exist: redirect:/test/index.foo rewrite log 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (5) hook_uri2file: r->uri: /a, r->filename: (null), r->the_request: GET /a HTTP/1.1, e->handler (null) 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (5) [perdir /var/www/] hook_fixup: r->uri: /a, r->filename: /var/www/a, r->the_request: GET /a HTTP/1.1, r->handler (null) 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/a -> a 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (3) [perdir /var/www/] applying pattern '^a' to uri 'a' 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (2) [perdir /var/www/] rewrite 'a' -> '/test/index.foo' 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (2) [perdir /var/www/] remember /test/index.foo to have Content-handler 'application/x-cgi-php' 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (1) [perdir /var/www/] internal redirect with /test/index.foo [INTERNAL REDIRECT] 127.0.0.1 - - [31/Aug/2006:17:58:50 +0200] [localhost/sid#27bfb8][rid#f53df0/initial] (1) force filename redirect:/test/index.foo to have the Content-handler 'application/x-cgi-php' ======================================================= full request processing order. Note: This uses the "mod_dir hack", otherwise the processing would end with "mod_dir: hook fixup_dir" RewriteEngine on RewriteRule ^test/lib$ /test/data [L] lib and data are existing folders Request: /test/lib [Thu Aug 31 17:13:33 2006] [debug] request.c(111): [client 127.0.0.1] ##############ap_process_request_internal()############## with r->parsed_uri.path /test/lib, r->the_request: GET /test/lib HTTP/1.1, d->handler: (null) [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4149): [client 127.0.0.1] mod_rewrite: hook hook_uri2file with r->uri: /test/lib, r->filename: (null), r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4424): [client 127.0.0.1] mod_rewrite: hook hook_fixup with r->uri: /test/lib, r->filename: /var/www/test/lib, r->handler: (null), dconf->directory: /var/www/, r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4691): [client 127.0.0.1] mod_rewrite: hook hook_fixup: setting r->handler = redirect-handler; with r->uri: /test/lib, r->filename: redirect:/test/data, r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] mod_dir.c(104): [client 127.0.0.1] mod_dir: hook fixup_dir with r->uri: /test/lib, r->filename: redirect:/test/data, r->handler: redirect-handler # without the temporarily mod_dir hack, mod_dir would now force a redirect to /test/lib/ and the internal processing ends. [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4712): [client 127.0.0.1] mod_rewrite: hook hook_mimetype with r->uri: /test/lib, r->filename: redirect:/test/data, r->handler: redirect-handler, r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4742): [client 127.0.0.1] mod_rewrite: hook handler_redirect with r->uri: /test/lib, r->filename: redirect:/test/data, r->handler: redirect-handler, r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] http_request.c(468): [client 127.0.0.1] ====ap_internal_redirect()==== with r->uri: /test/lib, new_uri: /test/data, r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] request.c(111): [client 127.0.0.1] ##############ap_process_request_internal()############## with r->parsed_uri.path /test/data, r->the_request: GET /test/lib HTTP/1.1, d->handler: (null) [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4149): [client 127.0.0.1] mod_rewrite: hook hook_uri2file with r->uri: /test/data, r->filename: (null), r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] mod_rewrite.c(4424): [client 127.0.0.1] mod_rewrite: hook hook_fixup with r->uri: /test/data, r->filename: /var/www/test/data, r->handler: (null), dconf->directory: /var/www/, r->the_request: GET /test/lib HTTP/1.1 [Thu Aug 31 17:13:33 2006] [debug] mod_dir.c(104): [client 127.0.0.1] mod_dir: hook fixup_dir with r->uri: /test/data, r->filename: /var/www/test/data, r->handler: (null) 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (5) hook_uri2file: r->uri: /test/lib, r->filename: (null), r->the_request: GET /test/lib HTTP/1.1, r->handler (null) 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (5) [perdir /var/www/] hook_fixup: r->uri: /test/lib, r->filename: /var/www/test/lib, r->the_request: GET /test/lib HTTP/1.1, r->handler (null) 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/test/lib -> test/lib 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (3) [perdir /var/www/] applying pattern '^(test)/lib$' to uri 'test/lib' 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (4) [perdir /var/www/] RewriteCond: input='' pattern='!index' => matched 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (2) [perdir /var/www/] rewrite 'test/lib' -> '/test/data' 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f24c70/initial] (1) [perdir /var/www/] internal redirect with /test/data [INTERNAL REDIRECT] # without the temporarily mod_dir hack, mod_dir would now force a redirect to /test/lib/ 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f39070/initial/redir#1] (5) hook_uri2file: r->uri: /test/data, r->filename: (null), r->the_request: GET /test/lib HTTP/1.1, r->handler (null) 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f39070/initial/redir#1] (5) [perdir /var/www/] hook_fixup: r->uri: /test/data, r->filename: /var/www/test/data, r->the_request: GET /test/lib HTTP/1.1, r->handler (null) 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f39070/initial/redir#1] (3) [perdir /var/www/] strip per-dir prefix: /var/www/test/data -> test/data 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f39070/initial/redir#1] (3) [perdir /var/www/] applying pattern '^(test)/lib$' to uri 'test/data' 127.0.0.1 - - [31/Aug/2006:17:13:33 +0200] [localhost/sid#27bfb8][rid#f39070/initial/redir#1] (1) [perdir /var/www/] pass through /var/www/test/data # now, after pass through, mod_dir should act and force a redirect to /test/data/. If there would be an other internal redirect eg. now to /index.php, mod_dir should not act on /test/data (but it does without the hack)