0

I'm stuck with an NGINX rewrite rule and hope you can help me out or point into the right direction. My problem looks like this:

I want to rewrite an URL if a specific argument appears. For example argument=1 like this: www.old_domain.com?argument=1&id=1&l=dfsdgsh

If this argument flag appears, redirect it to another domain, but keep the part after argument=1. For example redirect to: www.new_domain.com?id=1&l=dfsdgsh

I understand how to redirect the whole old domain to a new domain, but I'm having trouble to understand how to identify the argument flag and then how to take the last part to the new domain.

Cheers, Szop

1 Answer 1

3

Example:

if ( $args ~ argument=([0-9]+)&id=1&l=([\w]+) ) {
    set $arg  $1;
    set $l $2;
 }

if ( $arg = 1) {
   rewrite (.*)  http://domain1/?id=$arg&l=$l?;
}

if ( $arg = 2) {
       rewrite (.*)  http://domain2/?id=$arg&l=$l?;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.