Sometimes it is necessary to modify the RequestURI, to strip some GET-pairs. Here is a way how this could be done using nginx. Though we all know that if is evil, it’s sometimes quite handy.
# the »Evil Facebook-Like-Hack.«
location / {
# initialize variables with empty values
set $01 "";set $02 "";set $03 "";set $04 "";
set $05 "";set $06 "";set $07 "";set $08 "";
# if GET key exists, copy its value
if ($arg_productName) { set $01 productName=$arg_productName;}
if ($arg_linkId) { set $02 linkId=$arg_linkId;}
if ($arg_target) { set $03 target=$arg_target;}
if ($arg_id) { set $04 id=$arg_id;}
if ($arg_linkValue) { set $05 linkValue=$arg_linkValue;}
if ($arg_groupId) { set $06 groupId=$arg_groupId;}
if ($arg_articleId) { set $07 articleId=$arg_articleId;}
if ($arg_version) { set $08 version=$arg_version;}
# if a GET-key has fb_ in its name then do the funky URL-magic.
if ($args ~* fb_ ) {
# clear the GET-array so that the URI has no GET-pairs
set $args "";
# rewrite the given URL and add the GET-pairs we create above
rewrite ^ $scheme://$host$uri?$01$02$03$04$05$06$07$08 break;
}
}
The only drawback is that the URL we receive contains at least a ? for a case when none of the given keys exists – but that’s a minor thing I’d say.