Redirect specific query to a page

Vadim Lazovskiy vadim.lazovskiy at gmail.com
Sun Jan 20 13:00:03 UTC 2013


Hello,

http://nginx.org/en/docs/http/ngx_http_map_module.html
Before version 0.9.0 only a single variable could be specified in the first
parameter.

map $arg_option$arg_view$arg_id$arg_itemid $redirect_uri {
      com_contentarticle40106 /blahblah/page1;
      com_contentarticle164139 /blahblah/page2;
}

...

location / {
      if ($redirect_uri) {
            return 301 $scheme://$host$redirect_uri;
      }
}

It's also order-independent. And this is an Orthodox way :)


2013/1/20 António P. P. Almeida <appa at perusio.net>

> 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
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>



-- 
Best Regards,
Vadim Lazovskiy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20130120/cef0d088/attachment.html>


More information about the nginx mailing list