Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx rewrite that includes a blank spce

Tags:

nginx

rewrite

A client of ours has created a QR code that includes a blank space in the url. How would I write an nginx redirect that dealt with this problem?

A couple of attempts using things like "%20" in the string seem to cause nginx to error or fail the configtest

To be precise the QR code reads like this

http://www.google.com/somestuff /someotherstuf/pagewewant

and I need to re direct it to

http://www.google.com/somestuff/someotherstuf/pagewewant (The re write should show no blank space after somestuff )

Thanks for your time

like image 489
user1621262 Avatar asked Aug 24 '12 00:08

user1621262


1 Answers

Question is over two years old, but maybe it'll save someone some headaches.

Word of warning: I am no nginx expert. It's just one the things I tried after finding this unanswered question and it happened to work. It may not be the best way to do that. I would recommend checking the nginx documentation in case one is looking at handling a significantly large amount of such locations.

For the occasional rewrite including spaces I put the path in single quotes:

location '/level_one /landingpage.htm' { 
rewrite ^ http://www.foo.bar/level_one/landingpage.htm permanent; }

If for some reason you need to have spaces in the target put that in single quotes as well:

location '/downloads/foo bar.pdf' { 
rewrite ^ 'http://www.foo.bar/documents/foo bar.pdf' permanent; }
like image 120
mazerraxuz Avatar answered Oct 13 '22 00:10

mazerraxuz