Redirect specific query to a page

António P. P. Almeida appa at perusio.net
Sun Jan 20 02:43:18 UTC 2013


On 20 Jan 2013 02h28 CET, ondanomala_albertelli at yahoo.it wrote:

> I tried it but I get the error "nginx: [emerg] "set" directive is
> not allowed here" (as you said I put set and map at http level and
> rewrite at server level).
>

Indeed. set is not allowed at the http level, although it could be
quite useful IMHO. Either that or allowing to combine variables as the
left side of the map.

You have to do a more complex mapping. Remove the set and use the
following map instead (while mantaining the if at the server level):

map $query_string $new_uri {
    option=com_content&view=category&id=40&Itemid=106 /blahblah/page1;
    option=com_content&view=article&id=164&Itemid=139 /blahblah/page2;
    ## add as query string -> new uri lines as needed.
}

Now it depends on the order, which is bad. Other option is to use only
set and if. Like this:

At the server level:

## String composed of all the arguments on the URI.
set $arg_str $arg_option$arg_view$arg_id$arg_itemid;

if ($arg_str = com_contentarticle40106) {
   rewrite ^ $scheme://$host/blahblah/page1 permanent;
}

if ($arg_str = com_contentarticle164139) {
   rewrite ^ $scheme://$host/blahblah/page2 permanent;
}

Add as many if blocks as needed.

It's ugly but since you have only a few redirects, it's manageable
IMHO. Now you no longer depend on the order.

--- appa



More information about the nginx mailing list