Reputation: 597
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
Upvotes: 0
Views: 1052
Reputation: 674
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?;
}
Upvotes: 3