You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sebastian Färber <fa...@gmail.com> on 2010/07/16 14:39:39 UTC

ap_internal_fast_redirect / mod_dir and mod_rewrite interaction

Hi,

I've been debugging a weird issue that came up while switching from
Apache 1.3 to Apache 2.2.15
and I need a little hint in the right direction.
The problem seems to be that mod_dir is using
ap_internal_fast_redirect and because of that
mod_rewrite doesn't work on the correct URL Path that mod_dir has set.

---
DirectoryIndex index.html
RewriteEngine On
RewriteRule index\.html /temp.html [R,L]
---

This RewriteRule never matches, I'd have to change that to
"RewriteRule ^$ /temp.html [R,L]" (which
i don't want to because i have to make sure no changes to RewriteRules
are necessary when switching
from 1.3 to 2.2).

I tried converting mod_dir.c from ap_internal_fast_redirect to just
ap_internal_redirect which solves
my problem but i'm not sure if this is the right fix? The fix also
causes mod_autoindex to complain
in the error log (Options Indexes is disabled) because the request
gets handed to the next module after
redirection.

Any advice would be appreciated, is there a way i can use
ap_internal_redirect in mod_dir.c and make
sure mod_autoindex.c doesn't get run afterwards (if i redirected)?


-- Sebastian

Re: ap_internal_fast_redirect / mod_dir and mod_rewrite interaction

Posted by Sebastian Färber <fa...@gmail.com>.
> "have to make sure no changes"?  That's an oxymoron, you are changing your
> product significantly.  You might look at mod_version if you want conditional
> behavior (you would need it installed for both 1.3 and 2.2, of course).  Alt,
> you can always add a -D AP22 or similar to your 2.2 startup scripts.

You're right, but nothing wrong with trying to minimize the necessary
changes? :-)
Thanks for the pointer to mod_version, I'll have a look.


>> I tried converting mod_dir.c from ap_internal_fast_redirect to just
>> ap_internal_redirect which solves
>> my problem but i'm not sure if this is the right fix?
>
> Such a fix won't be incorporated by httpd for 2.2 (or 2.0) since these are
> constant in terms of their expected behavior from subver to subver.
>
> You will probably be glad to hear we are dropping internal_fast from 2.4 due
> to the number of side effects it causes, esp in 3rd party modules.

I'm fine with patching this locally ... but after applying my patch
(see at the end of my mail)
i always get an error in my log from mod_autoindex - complaining that
"Options Indexes" isn't set.
I'm puzzled why mod_autoindex is even running, mod_dir took care of
the translation from "/" -> "/index.html".
Any ideas or pointers? Would be great!


-- Sebastian

--- /httpd-2.2.15/modules/mappers/mod_dir.c   2006-07-12
05:38:44.000000000 +0200
+++ modules/mappers/mod_dir.c   2010-07-16 16:55:15.000000000 +0200
@@ -195,7 +195,12 @@ static int fixup_dir(request_rec *r)
         if (rr->status == HTTP_OK
             && (   (rr->handler && !strcmp(rr->handler, "proxy-server"))
                 || rr->finfo.filetype == APR_REG)) {
-            ap_internal_fast_redirect(rr, r);
+            char *new_uri = ap_escape_uri(r->pool, rr->uri);
+            if (rr->args != NULL)
+               new_uri = apr_pstrcat(r->pool, new_uri, "?", rr->args, NULL);
+            else if (r->args != NULL)
+               new_uri = apr_pstrcat(r->pool, new_uri, "?", r->args, NULL);
+             ap_internal_redirect(new_uri, r);
             return OK;
         }

Re: ap_internal_fast_redirect / mod_dir and mod_rewrite interaction

Posted by "William A. Rowe Jr." <wr...@rowe-clan.net>.
On 7/16/2010 7:39 AM, Sebastian Färber wrote:
> RewriteRule index\.html /temp.html [R,L]
> 
> This RewriteRule never matches, I'd have to change that to
> "RewriteRule ^$ /temp.html [R,L]" (which
> i don't want to because i have to make sure no changes to RewriteRules
> are necessary when switching
> from 1.3 to 2.2).

"have to make sure no changes"?  That's an oxymoron, you are changing your
product significantly.  You might look at mod_version if you want conditional
behavior (you would need it installed for both 1.3 and 2.2, of course).  Alt,
you can always add a -D AP22 or similar to your 2.2 startup scripts.

> I tried converting mod_dir.c from ap_internal_fast_redirect to just
> ap_internal_redirect which solves
> my problem but i'm not sure if this is the right fix?

Such a fix won't be incorporated by httpd for 2.2 (or 2.0) since these are
constant in terms of their expected behavior from subver to subver.

You will probably be glad to hear we are dropping internal_fast from 2.4 due
to the number of side effects it causes, esp in 3rd party modules.