Re: Rewrite domain.com to other domain.com/dir/subdir

2014-06-18 Thread Willy Tarreau
Hi Matt,

[ please avoid top-posting, it's very unconvenient to reply with the context,
  rearranging your mail now ]

On Wed, May 28, 2014 at 11:40:55PM +0200, Matt . wrote:
 2014-05-28 23:28 GMT+02:00 Bryan Talbot bryan.tal...@playnext.com:
  The example in the reqirep section of the documentation seems to mostly do
  what you're asking.
 
 
  http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#reqirep
 
  Does that not work?
 
  This will rewrite foo.com/baz.jpg - newdomain.com/com/foo/baz.jpg
 
reqirep ^Host:\ foo.com Host:\ newdomain.com
reqirep ^GET\ /(.*) GET\ /com/foo/\1
 
 Yes I cam up to that part, but about the search in the map, do I need
 to do this twice ?

You could. In fact there's a trick you could use now which consists in
using the base sample as a key for two maps. base contains the
concatenation of the host name and the URI. For example :

   GET /foo/bar HTTP/1.1
   Host: blah.example.org

Then base will equal blah.example.org/foo/bar. I think you see
where I'm going now. You can simply build two maps, one for the
uri part and one for the Host part, both indexed on the base, and
retrieve each part from there.

Hmmm thinking a bit more about it, I'm seeing an issue here. I don't
see how I could replace part of a URI using sample fetch expressions :-(

Well, if you don't have too many URIs to replace, you could at least apply
them based on a condition (eg: if you only need to insert a few prefixes,
you could simply condition a few reqirep rule on the output of the URI map).

For example it could be more or less like this :

reqirep ^GET\ /(.*) GET\ /foo/\1 if { base,map(prefix.map) foo }
reqirep ^GET\ /(.*) GET\ /bar/\1 if { base,map(prefix.map) bar }
reqirep ^GET\ /(.*) GET\ /com/\1 if { base,map(prefix.map) com }
http-request set-header Host %[base,map(host.map)]

There will be a few tricks that might be needed (basically, the base for
setting the Host header will change due to the former rewrite), but before
going into details, I'd need to know if you think this is something that
could be acceptable.

Regards,
Willy




Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-28 Thread Bryan Talbot
On Wed, May 28, 2014 at 2:49 AM, Matt . yamakasi@gmail.com wrote:

 I'm still struggeling here and also looking at Varnish if it can
 accomplish it.


What have you tried and what part of that is not working as you expect?




 I think HA proxy is the way as I also use it for normal loadbalancing,
 but this is another chapter for sure...

 Any help is welcome!



-Bryan


Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-28 Thread Matt .
The normal redirect is working but convirt it to a rewrite is where I'm stuck.

Should I use an ACL upfront that looks in the map and do an if on that
or is the ACL not needed at all ?

As I was busy too look how Varnish can accomplish this (using a MySQL
Database) I need to check this again, but I know I was stuck at that
part already because of the various examples that do the same rewrites
in a different way.

2014-05-28 20:50 GMT+02:00 Bryan Talbot bryan.tal...@playnext.com:
 On Wed, May 28, 2014 at 2:49 AM, Matt . yamakasi@gmail.com wrote:

 I'm still struggeling here and also looking at Varnish if it can
 accomplish it.


 What have you tried and what part of that is not working as you expect?




 I think HA proxy is the way as I also use it for normal loadbalancing,
 but this is another chapter for sure...

 Any help is welcome!



 -Bryan




Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-28 Thread Bryan Talbot
On Wed, May 28, 2014 at 11:57 AM, Matt . yamakasi@gmail.com wrote:

 The normal redirect is working but convirt it to a rewrite is where I'm
 stuck.

 Should I use an ACL upfront that looks in the map and do an if on that
 or is the ACL not needed at all ?



The example in the reqirep section of the documentation seems to mostly
do what you're asking.


http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#reqirep

Does that not work?

This will rewrite foo.com/baz.jpg - newdomain.com/com/foo/baz.jpg

  reqirep ^Host:\ foo.com Host:\ newdomain.com
  reqirep ^GET\ /(.*) GET\ /com/foo/\1




-Bryan


Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-28 Thread Matt .
Hi Bryan,

Yes I cam up to that part, but about the search in the map, do I need
to do this twice ?

2014-05-28 23:28 GMT+02:00 Bryan Talbot bryan.tal...@playnext.com:
 On Wed, May 28, 2014 at 11:57 AM, Matt . yamakasi@gmail.com wrote:

 The normal redirect is working but convirt it to a rewrite is where I'm
 stuck.

 Should I use an ACL upfront that looks in the map and do an if on that
 or is the ACL not needed at all ?



 The example in the reqirep section of the documentation seems to mostly do
 what you're asking.


 http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#reqirep

 Does that not work?

 This will rewrite foo.com/baz.jpg - newdomain.com/com/foo/baz.jpg

   reqirep ^Host:\ foo.com Host:\ newdomain.com
   reqirep ^GET\ /(.*) GET\ /com/foo/\1




 -Bryan




Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-27 Thread Matt .
HI All,

I have searched a lot abotu this and it's not clear to me.

De we need to use ACL's in this matter or not. I can make a simple rewrite
but its unclear to me how to use the lookup from a map(file).

Any suggestions ?

Thanks!

Matt




2014-05-26 17:33 GMT+02:00 Matt . yamakasi@gmail.com:

 Hi Baptiste,

 OK, I also have seen examples (not for domains as I need them) that use
 ACL's in front.

 Waht do you think about that and can you give me some example ? It's kinda
 confusing what I found using google and mailinglists.

 Cheers,

 Matt


 2014-05-26 17:22 GMT+02:00 Baptiste bed...@gmail.com:

 On Mon, May 26, 2014 at 4:15 PM, Matt . yamakasi@gmail.com wrote:
  Hi All,
 
  In order to my earlier topic about redirecting a domainname I actually
 want
  to rewrite one too.
 
  Let's says I have domainname2.com and I want to show
  domainname.com/dir/subdir under that domain, can this be done with
 reqrep ?
 
  It seems that this is the way, but I cannot find any example that does
 so.
 
  Do I also need the forward option ?
 
  Thanks!
 
  Matt

 Hi Matt,

 You have to do a couple of reqirep/reqrep.
 One for the Host header, one for the URL path.

 Baptiste





Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-26 Thread Baptiste
On Mon, May 26, 2014 at 4:15 PM, Matt . yamakasi@gmail.com wrote:
 Hi All,

 In order to my earlier topic about redirecting a domainname I actually want
 to rewrite one too.

 Let's says I have domainname2.com and I want to show
 domainname.com/dir/subdir under that domain, can this be done with reqrep ?

 It seems that this is the way, but I cannot find any example that does so.

 Do I also need the forward option ?

 Thanks!

 Matt

Hi Matt,

You have to do a couple of reqirep/reqrep.
One for the Host header, one for the URL path.

Baptiste



Re: Rewrite domain.com to other domain.com/dir/subdir

2014-05-26 Thread Matt .
Hi Baptiste,

OK, I also have seen examples (not for domains as I need them) that use
ACL's in front.

Waht do you think about that and can you give me some example ? It's kinda
confusing what I found using google and mailinglists.

Cheers,

Matt


2014-05-26 17:22 GMT+02:00 Baptiste bed...@gmail.com:

 On Mon, May 26, 2014 at 4:15 PM, Matt . yamakasi@gmail.com wrote:
  Hi All,
 
  In order to my earlier topic about redirecting a domainname I actually
 want
  to rewrite one too.
 
  Let's says I have domainname2.com and I want to show
  domainname.com/dir/subdir under that domain, can this be done with
 reqrep ?
 
  It seems that this is the way, but I cannot find any example that does
 so.
 
  Do I also need the forward option ?
 
  Thanks!
 
  Matt

 Hi Matt,

 You have to do a couple of reqirep/reqrep.
 One for the Host header, one for the URL path.

 Baptiste