user1847844
user1847844

Reputation: 87

Redirect 2 urls (%20) to one in nginx

I have this problem that I can't solve. I have a nginx server that I have to make a redirect of this type.

http://midomain.com/xxxx/xxxx/ http://wikipedia.com/xx --> http://midomain.com/yyyy

As I have two urls with a space, there is no way to make it work.

I have tried multiple ways.

rewrite ^/xxxx/xxxx/\ http://wikipedia.com/xx http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/\ http://wikipedia.com/xx" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/%20http://wikipedia.com/xx http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/%20http://wikipedia.com/xx" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/\ http://wikipedia.com/xx/$ http://midomain.com/yyyy permanent;
rewrite "^/xxxx/xxxx/\ http://wikipedia.com/xx/$" http://midomain.com/yyyy permanent;
rewrite ^/xxxx/xxxx/%20http://wikipedia.com/xx/$ http://midomain.com/yyyy permanent;

I don't know if I'm doing something wrong.

Upvotes: 1

Views: 565

Answers (1)

Richard Smith
Richard Smith

Reputation: 49742

Nginx normalises the URI before processing it through rewrite. The %20 is resolved to a literal space character and consecutive / characters are replace by a single /. It's that last point that's causing you problems.

For example:

rewrite "^/xxxx/xxxx/ http:/wikipedia\.com/xx$" http://midomain.com/yyyy permanent;

Upvotes: 1

Related Questions