Welcome! Log In Create A New Profile

Advanced

URI Substitue _ with - and + with space

Posted by Thomas Glanzmann 
Thomas Glanzmann
URI Substitue _ with - and + with space
January 05, 2018 11:00AM
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
Sorry, only registered users may post in this forum.

Click here to login