Hi guys,
I’m trying to rewrite an url with a few parameters, but unsuccessfully.
The URL:
https://www.mysite.com.br/category-body/categories/promotionalXXX?utm_source=PromoCode&utm_medium=AddPromo&utm_campaign=PromoCode_AddPromo_moneycampaing
I need rewrite to:
https://www.mysite.com.br/digital-parts/newspaper/recs-xyaw-sazz-qqad-cxae
The /promotionalXXX can be /promotional123, /promotional324 and many
more
…
What i already tried:
rewrite
^/category-body/categories/promotional(.*)utm_source=PromoCode&utm_medium=AddPromo&utm_campaign=PromoCode_AddPromo_moneycampaing
https://www.mysite.com.br/digital-parts/newspaper/recs-xyaw-sazz-qqad-cxae;
and …
location = /category-body/categories/promotional(.*)$ {
if ($args ~
utm_source=PromoCode&utm_medium=AddPromo&utm_campaign=PromoCode_AddPromo_moneycampaing)
{
rewrite ^/digital-parts/newspaper/recs-xyaw-sazz-qqad-cxae; permanent;
}
}
But any of this worked for me…
What’s the best way to solve this?
Thanks!
On 5 December 2013 17:09, Raphael R. O. [email protected] wrote:
Hi guys,
I’m trying to rewrite an url with a few parameters, but unsuccessfully.
You’re almost there 
What i already tried:
rewrite
^/category-body/categories/promotional(.*)utm_source=PromoCode&utm_medium=AddPromo&utm_campaign=PromoCode_AddPromo_moneycampainghttps://www.mysite.com.br/digital-parts/newspaper/recs-xyaw-sazz-qqad-cxae;
“rewrite” doesn’t examine query strings, so if the contents of your
query string are required to drive your logic, you’ll need to use
other tools instead of (or well as) rewrite.
and …
location = /category-body/categories/promotional(.*)$ {
You probably don’t want the “=” here. I don’t actually know what a
regex (“(.*)”) location used alongside “=” will do. I’m slightly
surprised nginx didn’t complain on reload/restart …
Have a read of this section:
http://wiki.nginx.org/HttpCoreModule#location
You probably want to use a case-sensitive regex location.
if ($args ~
“utm_source=PromoCode&utm_medium=AddPromo&utm_campaign=PromoCode_AddPromo_moneycampaing”)
I’d use a map{} variable inside the if(), personally. The map can use
the same check as that which you have above, but in a way which
abstracts the actual check away from the logic that it drives. This is
just a stylistic change however 
HTH,
Jonathan