Welcome! Log In Create A New Profile

Advanced

Rewrite rule to append GET parameter

Posted by AS 
AS
Rewrite rule to append GET parameter
August 04, 2011 04:02AM
Hello everyone.
I am having problems appending an additional GET parameter to a request received. Let's say I have an URL like this:

http://1.2.3.4/wrapper/wrapper.html?viewer_id=555&viewer_type=2&secret=1234&language=0&referrer=profile&lc_name=1234

What I would like to get is to append a new GET parameter skip_maintenance when viewer_id equals to 555. So I would like to see something like

http://1.2.3.4/wrapper/wrapper.html?viewer_id=555&viewer_type=2&secret=1234&language=0&referrer=profile&lc_name=1234&skip_maintenance

I have tried many different ways around my config and found "if" construction fits my needs enough. But when the actual rewrite happens many weird things appears. What do I have now is this piece of config file:

-----------------------------------------------------------------------------------------------
server {
server_name _;
listen 80;
error_log /var/log/nginx/site-error.log debug;
access_log /var/log/nginx/site-access.log main;

location / {
root /usr/share/site/www_content/active/;
index index.html index.htm;
if ($args ~ user_id=555) {
rewrite ^ http://$server_addr$uri$is_args$args&skip_maintenance? break;

}

}
}
-----------------------------------------------------------------------------------------------

This config almost make things look like what I need. "If" part works as it should but when it comes to rewrite part I am getting this error: "The page isn't redirecting properly"

In error log I can see:

2011/08/04 11:48:35 [notice] 2934#0: *1 rewritten redirect: "http://1.2.3.4/wrapper/wrapper.html?viewer_id=555&viewer_type=2&secret=1234&language=0&referrer=profile&lc_name=1234&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance&skip_maintenance"

So I have repeatable parameter here and I cannot get rid of this anyhow. I've tried rewrite permanent, last, with and without "?" at the end but with no luck. If I cut off "http://$server_addr" part I am getting full path to wrapper.html file with 404.

Any clues or ideas to get it work will be greatly appreciated.

My Nginx is 0.8.53
AS
Re: Rewrite rule to append GET parameter
August 05, 2011 05:56AM
I believe this is really useful feature and it is a pity it is not being described anywhere. Having possibility to add some GET parameter on the nginx side based on some URL data may simply hide some debugging or service features from public.



Edited 1 time(s). Last edit at 08/05/2011 05:57AM by AS.
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