Re: redirecting many urls

From: Matt <mattmoran76#gmail.com>
Date: Fri, 4 Dec 2009 14:10:19 +0000


Replying to the list for archive / searching purposes.

Hi Chris,

These rules aren't good practice, just needed to be done for cosmetic reasons for our application :-S

Basically you may want to redirect a lot of requests with a 301,302, or 303 code but only have one rule.

I wanted many usersN pages i.e. http://mydomain.com/users1/page to redirect with a 301 code to http://mydomain.com/users1/mypage

This will rewrite/proxy /users1/page to /users1/mypage - reqrep ^([^\ ]*)\ /([a-z]+)/page(.*) \1\ /\2/mypage\3

Now I want to redirect those pages so set up a acl to capture the proxied URL - acl users_redirect1 url_reg /([a-z]+)/mypage

This will capture the proxied pages, now I can redirect them with just a prefix as the URL i'm redirecting has already been rewritten. - redirect prefix http://mydomain.com code 301 if users_redirect1

Obviously when the redirect comes back the rule could redirect it again, but I already have a rule before all of the above that rewrites that. i.e.

Hope this makes sense.

Thanks,

Matt

2009/12/4 Chris Sarginson <chris#sargy.co.uk>:
> I didnt quite follow Willy on this - any chance you could provide a sample,
> as this sounds like something we could do well to use in future?
>
> Cheers
> Chris
>
> Matt wrote:
>>
>> Willy that makes perfect sense, can't believe I didn't see it earlier.
>>  Testing it right now and it appears to work fine.
>>
>> Many thanks,
>>
>> Matt
>>
>> 2009/12/3 Willy Tarreau<w#1wt.eu>:
>>>
>>> Hi Matt,
>>>
>>> replying quickly this time.
>>>
>>> On Thu, Dec 03, 2009 at 10:13:57AM +0000, Matt wrote:
>>>>
>>>> Hi Willy, sure.
>>>>
>>>> I guess what i'd be writing with my knowledge of haproxy at the moment
>>>> is one of these for every user:-
>>>>
>>>> acl user1 url_beg /user1/mypage
>>>> redirect location http://mysite.com/user1/page code 301 if user1
>>>>
>>>> It would be great if I could do:
>>>> acl user1 url_reg /(.*)/mypage
>>>> redirect location http://mysite.com/\1/page code 301 if user1
>>>>
>>>> Prefix doesn't work in this context as the thing I want to change is
>>>> after the value i'm capturing.
>>>>
>>>> I've tried to think about how I could do it with the reqrep and rsprep
>>>> but i'm finding it hard to get my head round.  Especially since I
>>>> really wouldn't like the request to hit a server when I want to
>>>> redirect them.
>>>
>>> OK. What I think you should try, though I've not tested it, is to
>>> first rewrite the request using "reqrep" and put the fields in the
>>> order you like, then perform a prefix-based redirect. I think it
>>> should work, but there may be corner cases I'm not thinking about.
>>>
>>> Regards,
>>> Willy
>>>
>>>
>>
>
Received on 2009/12/04 15:10

This archive was generated by hypermail 2.2.0 : 2009/12/04 15:15 CET