Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have multiple apache rewrite with different Query_String to convert to nginx:

 ServerName oldsite.com 
 RewriteCond %{QUERY_STRING} ^ubb=showflat&Number=662213$ 
 RewriteRule ^/ubbthreads/ubbthreads.php$ http://newsite.com/1/? [R=301,NC,L]
 RewriteCond %{QUERY_STRING} ^ubb=showflat&Number=662214$ 
 RewriteRule ^/ubbthreads/ubbthreads.php$ http://newsite.com/2/? [R=301,NC,L]

-->

server {
    listen       80;
    server_name  oldsite.com;
    location ~ /ubbthreads/{
        if ($arg = "ubb=showflat&Number=662213"{
        rewrite ^ubbthreads/ubbthreads.php http://newsite.com/1/? permanent;
        }
        if ($arg = "ubb=showflat&Number=662214"{
        rewrite ^ubbthreads/ubbthreads.php http://newsite.com/2/? permanent;
        }
    }

Is that the correct way ? Is there another way to do this without if ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You might be able to use a map for it.

map $arg_Number $new {
    662213 http://newsite.com/1/?
    662214 http://newsite.com/2/?
}

and then in your location

rewrite ^ $new permanent;

Do note that you can only avoid the if when you redirect every request to that location. If you need to redirect only when Number is something specific or if it's set then you cannot avoid an if and in worse case scenario (only when something specific) you can't use the map at all.

share|improve this answer
    
Thanks, it worked, note that the trailing "?" has to be in the rewrite and not in the map: rewrite ^ $new? permanent; –  Bastien974 Feb 15 '13 at 19:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.