httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Neil A. Hillard" <>
Subject Re: [users@httpd] mod_rewrite with [last] not behaving as expected
Date Thu, 20 Jul 2006 10:01:24 GMT

Nick Burch wrote:
> Hi All
> I've been trying to set up some rewriting rules with mod_rewrite, and
> discovered that even with a [last] directive, things aren't quite
> behaving as I'd expect.
> My config is perhaps slightly unusual, in that I have a default rule
> that applies, at the bottom of the rewrite block. The config is
> something like:
> DocumentRoot /var/www/foo/
> <Directory /var/www/foo/>
>     RewriteEngine on
>     RewriteRule ^foo/foo.xsd /schema/foo.xsd [last]
>     RewriteRule ^foo/.* /schema/about_foo.html [last]
>     RewriteRule .* http://somewhere-else/ [R]
> </Directory>
> Turning on RewriteLog and RewriteLogLevel, I see that a request for
> /foo/bar is re-written as an internal redirect to
> /schema/about_foo.html. No further rewriting occurs. The problem is that
> apache decides that it then needs to start processing
> /schema/about_foo.html from the top of my rewriting block, since it too
> falls within the Directory. It then runs off, does more rewriting, and
> goes to the wrong place.
> In short, the [last] directive stops this re-writing run, but doesn't
> prevent further runs.
> Is this behaviour:
> a) expected (except by me!) or unexpected?
> b) if expected, should we add another mod_rewrite flag to prevent further
>     mod_rewrites touching the request? (eg [nofurther])
> (For anyone suffering the same issue, my workaround was to add a
> <Directory> for the schema subdir, with RewriteEngine on, but no rules)

Yes it is expected - it is not Apache deciding to run the URL through
the rewriting.  A redirect will be sent to the client which will then
request the new target and it is that which will be run through the
rewriting rules.

I would suggest that you'd be better off with rewriting in a Location
block and not a Directory.  The rewriting relates to the URL and not
necessarily the file system.

If you retain those rewrites then every request will end up at

Do you really want to perform a redirect - in which case you need to
exclude /schema/ from 'catchall' last rewrite, or you need to proxy them
(use [P,L]).



Neil Hillard          
Westland Helicopters Ltd.

Disclaimer: This message does not necessarily reflect the
            views of Westland Helicopters Ltd.

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message