Welcome! Log In Create A New Profile

Advanced

Re: Redirect specific query to a page

Vadim Lazovskiy
January 20, 2013 08:02AM
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@perusio.net>

> On 20 Jan 2013 02h28 CET, ondanomala_albertelli@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@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>



--
Best Regards,
Vadim Lazovskiy
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Redirect specific query to a page

OndanomalA January 18, 2013 08:22PM

Re: Redirect specific query to a page

António P. P. Almeida January 18, 2013 08:54PM

Re: Redirect specific query to a page

OndanomalA January 19, 2013 09:46AM

Re: Redirect specific query to a page

António P. P. Almeida January 19, 2013 01:00PM

Re: Redirect specific query to a page

OndanomalA January 19, 2013 08:30PM

Re: Redirect specific query to a page

António P. P. Almeida January 19, 2013 09:44PM

Re: Redirect specific query to a page

Vadim Lazovskiy January 20, 2013 08:02AM

Rewrite rules with NGinx

miky January 20, 2013 10:24AM

Re: Rewrite rules with NGinx

Francis Daly January 20, 2013 10:52AM

Re: Rewrite rules with NGinx

miky January 20, 2013 11:36AM

Re: Rewrite rules with NGinx

Francis Daly January 20, 2013 12:02PM

Re: Rewrite rules with NGinx

António P. P. Almeida January 20, 2013 12:24PM

Re: Redirect specific query to a page

OndanomalA January 20, 2013 07:18AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 238
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready