httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Mearns <mearn...@gmail.com>
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 <mr3789@gmail.com> wrote:
> Hi everyone,
>
> I have the following rules with mod_rewrite:
>
> RewriteEngine on
> RewriteCond %{HTTP_HOST} ^www\.example\.com$
> RewriteRule ^blog/(.*?)$ http://blog.example.com/$1 [P]
>
>
> RewriteCond %{HTTP_HOST} ^example.com$
>
> RewriteRule ^(.*)?$ http://www.example.com/$1 [L,R=301]
>
> What I'm trying to achieve, and it works up to 90% of my expectations, is
> that any hits to http://www.example.com/blog proxies over to
> http://blog.example.com. They're two physically separate boxes.
>
> The issue I have here is that if I visit
> http://blog.example.com/some/dir/foo.php it works fine. However, if I go to
> http://www.example.com/blog/some/dir/foo.php, 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 http://www.example.com/blog to http://blog.example.com/
> ?
>
> 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
http://www.example.com/blog/some/dir/foo.php ? Does it work without
the "/some/dir", e.g., if you just go to
http://www.example.com/blog/foo.php ?


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
helps.

Second is that the ? is a little wierd in your rewrite rule:
RewriteRule ^blog/(.*?)$ http://blog.example.com/$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
is.

Hope some of that helps, good luck!
-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message