Menu

#1642 Change one url parameter value with redirect

3.0.15
closed
5
2016-03-25
2014-05-23
vertebrac
No

Hi guys!!
I'v been working on the last few days, trying to change just one value of a parameter for a given domain.

Ej: Whenever a request like this is made:

http://testsite.com/?toChange=foo&notToChange=bar1&notToChange=bar2

i'll need to change the "toChange" parameter to ej: bar0, so after the redirect, i need to get something like this:

http://testsite.com/?toChange=bar0&notToChange=bar1&notToChange=bar2

I almost get it done with this:

{+redirect{s@^http://testsite.com/\?toChange=[^&](.)@http://testsite.com/?toChange=bar0$1@}}
testsite.com

But the problem with this last statement, is that erases everything behind the first parameter, so i end with something like this:

http://testsite.com/?toChange=bar0

instead of:
http://testsite.com/?toChange=bar0&notToChange=bar1&notToChange=bar2

Can you give me a clue about what i’m doing wrong?

Thanks!!

Discussion

  • Fabian Keil

    Fabian Keil - 2014-05-25

    One problem is that the URL pattern will match the redirected URL, so the client will get redirected again (and again and again ...).

    Another problem is that "^&" matches two characters of which the first one can't be an ampersand (&). This is probably not what you meant.

    You could try something like:

    {+redirect{s@toChange=[^&]+@toChange=bar0@}}
    example.com/.*toChange=(?!bar0)

     
  • vertebrac

    vertebrac - 2014-05-26

    Works like a charm!
    Thanks so much! Fabian!!

     
  • Fabian Keil

    Fabian Keil - 2014-05-27

    You're welcome. Thanks for the confirmation.

     
  • Fabian Keil

    Fabian Keil - 2016-03-25
    • status: open --> closed
    • assigned_to: Fabian Keil
     

Log in to post a comment.