httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Mearns <>
Subject Re: [users@httpd] Question for using mod_rewrite to do proxying
Date Tue, 24 Feb 2009 00:34:53 GMT
On Mon, Feb 23, 2009 at 11:20 AM, Michael Roberts <> wrote:
> Hi everyone,
> I have the following rules with mod_rewrite:
> RewriteEngine on
> RewriteCond %{HTTP_HOST} ^www\.example\.com$
> RewriteRule ^blog/(.*?)$$1 [P]
> RewriteCond %{HTTP_HOST} ^$
> RewriteRule ^(.*)?$$1 [L,R=301]
> What I'm trying to achieve, and it works up to 90% of my expectations, is
> that any hits to proxies over to
> They're two physically separate boxes.
> The issue I have here is that if I visit
> it works fine. However, if I go to
>, it does not work properly.
> Is there a major flaw in my rules that's preventing me from doing this proxy
> of all requests from to
> ?
> Thanks all!

First, just in case you're unaware, there is a mod_proxy which might
be better suited to what you're doing, unless you have a specific
reason for not using it.

How exactly is it not working? What behavior do you see when you go to ? Does it work without
the "/some/dir", e.g., if you just go to ?

I can see a few things off hand, but not if they're causing the problem.

First, I always start my rewrite rules (the ones that are supposed to
be anchored at the beginning of the URI) with "^/", where as you just
have "^". I'm not sure if mod_rewrite is smart enough to handle the
difference, but I think the canonical URI that the pattern gets
matched against does in fact start with a '/', so if the module isn't
smart enough to automatically insert that, then your pattern isn't
going to match. It looks like all the examples in the doc start with
"^/" as well, so I would definitely give that a try and see if it

Second is that the ? is a little wierd in your rewrite rule:
RewriteRule ^blog/(.*?)$$1 [P]
I know some regex engines support a reluctant match, not sure if this
is what you're going for, and not sure if mod_rewrite supports it, but
it any event, I don't think it serves any purpose since there's
nothing after it, and it may very well be screwing things up.

In any event, your first step in debugging rewrite issue should always
be to turn on your rewrite log. This will help you find out what, if
any, of your rules are actually getting matched, and what the result

Hope some of that helps, good luck!

Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from:

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