Welcome! Log In Create A New Profile

Advanced

URI Substitue _ with - and + with space

Thomas Glanzmann
January 05, 2018 04:56AM
Hello,
I would like to substitue '_' with '-' and '+' with ' ' in the $URI and
pass it to upstream server that can't handle _ and + in the URI (IIS).

Based on [1] I found a working solution, however I would like to know if
there is a more efficient way to do the same for example using lua?

location / {
rewrite ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7-$8-$9;
rewrite ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5;
rewrite ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3;
rewrite ^([^_]*)_(.*)$ $1-$2;

rewrite ^([^+]*)\+([^+]*)\+([^+]*)\+([^+]*)\+([^+]*)\+([^+]*)\+([^+]*)\+([^+]*)\+(.*)$ $1%20$2%20$3%20$4%20$5%20$6%20$7%20$8%20$9;
rewrite ^([^+]*)\+([^+]*)\+([^+]*)\+([^+]*)\+(.*)$ $1%20$2%20$3%20$4%20$5;
rewrite ^([^+]*)\+([^+]*)\+(.*)$ $1%20$2%20$3;
rewrite ^([^+]*)\+(.*)$ '$1 $2';

proxy_pass https://upstream/;
}

[1] https://stackoverflow.com/questions/15912191/how-to-replace-underscore-to-dash-with-nginx

Cheers,
Thomas
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

URI Substitue _ with - and + with space

Thomas Glanzmann January 05, 2018 04:56AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 231
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