Home > Mobile >  nginx should add parameter if special header is present
nginx should add parameter if special header is present

Time:06-30

is there any simple way with nginX to add a parameter to the path ?
I am new to nginX and a bit confused with the configuration anyway. (long term Apache user) :

Example what I am trying to do:

Request Header : 

GET /xxxx/yyyy?page=10 HTTP/1.1.
x-my-special : true.

If (x-my-special is true) ; then 

  add_parameter(x-my-special=true) 


Result before the web application get it : 

Path : /xxxx/yyyy?page=10&x-my-special=true

Would be really nice if you could help or have a hint for me.

CodePudding user response:

If

/xxxx/yyyy?x-my-special=true&page=10

instead of

/xxxx/yyyy?page=10&x-my-special=true

will be ok to you, the simplest way will be

if ($http_x_my_special = true) {
    rewrite ^ $uri?x-my-special=true;
}

or, to add any non-empty value from the X-My-Special header:

if ($http_x_my_special) {
    rewrite ^ $uri?x-my-special=$http_x_my_special;
}

This if block should be placed at the server configuration level. However, depending on your actual config, it may come this block will be executed more than once, and the only way to place it properly will be to see your whole nginx configuration.

CodePudding user response:

Hey thank you for the reply. ATM the server config is nearly empty for that domain. Only php files are passed to fpm.

If :

/xxxx/yyyy?x-my-special=true&page=10
Or 
/xxxx/yyyy?page=10&x-my-special=true

Should make no differences. But will be "$http_x_my_special“ filled automatically by nginx if set ?

  • Related